Slide 1

Slide 1 text

Making asyncio on our own! Joongi Kim () Lablup / KossLab

Slide 2

Slide 2 text

Outline §    §   asyncio  async/await   §   : sleep  § Summary & Homework PyCon KR 2018

Slide 3

Slide 3 text

   Live Coding PyCon KR 2018

Slide 4

Slide 4 text

async/await  Live Coding PyCon KR 2018

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

 : sleep  Live Coding PyCon KR 2018

Slide 8

Slide 8 text

Hints § "async_sleep"          §   expire sleep ! task  •  %  )   "· !*  ? • ' $  &(/#  ) ? § select   timeout  " PyCon KR 2018

Slide 9

Slide 9 text

Summary PyCon KR 2018

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Summary • asyncio.Future –   Can    • asyncio.Task –   Task   • asyncio.BaseEventLoop –      § curio, trio    I/O      ! PyCon KR 2018

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

Thanks! PyCon KR 2018

Slide 14

Slide 14 text

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