【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