Zrób sobie asyncio
*dla ubogich
Cześć
mam na imię michał
programuję w C++
mieszkam w krakowie
Agenda
generatory
Pętla zdarzeń
sockety
context switching
czyli jak jednocześnie żuć gumę i iść po schodach
CONTEXT SWITCHing
yield
CONTEXT SWITCHing
NEXT()
CONTEXT SWITCHing
SEND()
CONTEXT SWITCHing
rysunek!
yield
yield
yield
yield
yield
CONTEXT SWITCHing
yield from
yield from
yield from
yield from
yield from
yield from
yield from
yield from
yield from
yield from
_i = iter(EXPR)
try:
_y = next(_i) # ------------------ "yield from"
except StopIteration as _e:
_r = _e.value
else:
while 1:
try:
_s = yield _y # ---------- "yield"
except GeneratorExit as _e:
try:
_m = _i.close
except AttributeError:
pass
else:
_m()
raise _e
except BaseException as _e:
_x = sys.exc_info()
try:
_m = _i.throw
except AttributeError:
raise _e
else:
try:
_y = _m(*_x)
except StopIteration as _e:
_r = _e.value
break
else:
try:
if _s is None:
_y = next(_i) # --- "next"
else:
_y = _i.send(_s)
except StopIteration as _e:
_r = _e.value
break
RESULT = _r
yield from
_i = iter(EXPR)
try:
_y = next(_i) # ------------------ "yield from"
except StopIteration as _e:
_r = _e.value
else:
while 1:
try:
_s = yield _y # ---------- "yield"
except GeneratorExit as _e:
try:
_m = _i.close
except AttributeError:
pass
else:
_m()
raise _e
except BaseException as _e:
_x = sys.exc_info()
try:
_m = _i.throw
except AttributeError:
raise _e
else:
try:
_y = _m(*_x)
except StopIteration as _e:
_r = _e.value
break
else:
try:
if _s is None:
_y = next(_i) # --- "next"
else:
_y = _i.send(_s)
except StopIteration as _e:
_r = _e.value
break
RESULT = _r
yield from
PEP 380
INPUT/OUTPUT
socket
INPUT/OUTPUT
BIND(), LISTEN(), ACCEPT()
INPUT/OUTPUT
recv()
INPUT/OUTPUT
sendall()
INPUT/OUTPUT
select.poll()
Pętla zdarzeń
BIEDA-ASyNCIO
w 5 minut
Dziękuję
mrzechonek/ghetto-asyncio
Bieda-Asyncio @ PyCon PL 2016
By Michał Lowas-Rzechonek
Bieda-Asyncio @ PyCon PL 2016
Implementacja głównej pętli, na kolanie
- 796