[Python]异步run_until_complete和run_forever
import asyncio
from asyncio import Future
async def f1():
print(1)
await asyncio.sleep(3)
print(2)
return "f1"
def callback(f: Future):
f.get_loop().stop()
loop = asyncio.get_event_loop()
task = loop.create_task(f1())
# 任务结束后回调终止
task.add_done_callback(callback)
# 循环
loop.run_forever()