【Python】Async异步等待简单例子理解
import time def run(coroutine): try: print("11") coroutine.send(None) except StopIteration as e: print("e.value",e.value) return e.value async def async_function(): time.sleep(2) print("等待两秒") return 1 async def await_coroutine(): await async_function() print("等待执行完成,再执行我") run(await_coroutine())
# 输出结果
11
等待两秒
等待执行完成,再执行我
e.value None