Python异步编程Async/Await
生活随笔
收集整理的這篇文章主要介紹了
Python异步编程Async/Await
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
python 從3.5開始從語言層面提供了新的異步編程語法。
import asyncioasync def hello():print("hello the world")r = await asyncio.sleep(1)print("hello again")def main():loop = asyncio.get_event_loop()""" tasks = [ asyncio.ensure_future(hello()), ] loop.run_until_complete(asyncio.wait(tasks)) """ print("begin")loop.run_until_complete(hello())print("end")loop.close()print("program is finished.")if __name__ == "__main__":main()總結
以上是生活随笔為你收集整理的Python异步编程Async/Await的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Akka Actor远程调用
- 下一篇: 现代c++之线程本地存储thread_l