owned this note changed 6 years ago
Linked with GitHub

Async contextmanager for Python 3.7 - Sammy Wen

歡迎來到 PyCon TW 2019 共筆

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

共筆入口:https://hackmd.io/@pycontw/2019
手機版請點選上方 按鈕展開議程列表。

PyCon Taiwan 2019 PyNight 活動規劃與 BoF 簽到/建立交流主題
https://hackmd.io/NaI9ymzRQ5urCvwOQ31WAA

從這開始

slide

asyncio vs Context manager

  • asyncio
    • concurrency in single thread
    • run tasks(wrapped coroutine) in an event loop
  • Context manager
    • PEP343 - the with statement
    • allow to allocate and release resource precisely when you want to.
    • 2 types of implement
      • Class
        • implement __enter__ and __exit__
      • Generate
        • add decorator @contextlib.contextmanager

async context manager

  • decorator @asynccontextmanger
  • class with __aenter__ and __aexit__ methods
  • asyncio.run(): 執行 co-routine
tags: PyConTW2019
Select a repo