【发布时间】:2019-12-29 23:51:22
【问题描述】:
我是 Python 异步编程的新手,我正在尝试编写一个示例协程,该协程一直等待,直到满足任意条件。这是实现它的正确方法吗?
async def foo():
print('foo') # this is executed before we start checking the condition
while not condition:
await asyncio.sleep(1)
print('bar') # this is executed after the condition is met
【问题讨论】:
-
正确的做法是使用
Events
标签: python python-3.x async-await python-asyncio