这是我的代码:
async def outer():
# if this while loop was not broken in 5 seconds, do something
while True:
# some code with breaks
通常我需要一个非阻塞异步定时器。
def outer():
async def loop():
#while loop here
task = asyncio.create_task(loop())
done, pending = await asyncio.wait([task], return_when=asyncio.FIRST_COMPLETED, timeout=5)
if task in done:
# loop has completed
else:
# loop is incomplete
一个同步io。等待