Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[PyCon KR 2018] Making asyncio on our own

[PyCon KR 2018] Making asyncio on our own

Joongi Kim

August 17, 2018
Tweet

More Decks by Joongi Kim

Other Decks in Programming

Transcript

  1. Outline §    §   asyncio 

    async/await   §   : sleep  § Summary & Homework PyCon KR 2018
  2. async/await  § PEP-380:      

     • yield from   : generator   generator •  caller   ! "(=generator)      ! " yield#    $  PyCon KR 2018
  3. async/await  § PEP-492 : async await   

    • yield from2 generator :4  – yield @04 <9,  def4 4  (func. vs generator) • yield from3  await  * 5 DI , >5:2... – async def (,  await /C ; : '%  # $ – await GJ= )2 async J% !+  : 6BE5& 7# L • async for, async with- 2 FI 7# 8 "A ? • LN async generator M3 1K yield @04  H.# PyCon KR 2018
  4. Hints § "async_sleep"       

      §   expire sleep ! task  •  %  )   "· !*  ? • ' $  &(/#  ) ? § select   timeout  " PyCon KR 2018
  5. Summary § asyncio    ! • ' +

    /2! 7 Future , yield4,  Future ,   8 4  1 3: –  await ;.,%#  7 Can , yield6 •  1  /2"  *90 ! - caller, ) event loop# 5 – # run() 6 8 • $ 8 event loop future" "book-keeping"8 6 – # WAIT_* &( 8 PyCon KR 2018
  6. Summary • asyncio.Future –   Can   

    • asyncio.Task –   Task   • asyncio.BaseEventLoop –      § curio, trio    I/O      ! PyCon KR 2018
  7. Homework § select *'$  selectors *'$ , . •

    kqueue / epoll !& % "  • select   kqueue / epoll / IOCP %   &% § Future "(+!  Can/Task . §  $  Can/Task - cancel!  , . • Cancellation $' :   vs. generator.close() § trio/curio )#  %!# & § Javascript async/await,  $ & •  generator vs. #  Promise PyCon KR 2018
  8. Reference § PEP 342 – Coroutines via Enhanced Generators §

    PEP 380 – Syntax for Delegating to a Subgenerator § PEP 492 – Coroutines with async and await syntax § PEP-3156 – Asynchronous IO Support Rebooted: the "asyncio" Module § Jonas Obrist's "Artisanal Asyncio Adventures" Talks § CPython's asyncio module source code on GitHub § curio (https://github.com/dabeaz/curio) § trio (https://github.com/python-trio/trio) PyCon KR 2018