【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




 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM