python协程用法案例
作者:
耍帅oldboy | 来源:发表于
2022-08-02 09:58 被阅读0次#coding=utf-8
import asyncio
import random
async def hello1(i):
print("Hello world"+i.__str__())
r = await asyncio.sleep(random.randint(1,10))
print("Hello agait"+i.__str__())
#模拟监听消息
async def amain():
i = 0
while True:
i = i + 1
asyncio.create_task(hello1(i))
await asyncio.sleep(1)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(amain())
本文标题:python协程用法案例
本文链接:https://www.haomeiwen.com/subject/flgdwrtx.html
网友评论