Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

AsyncIO

Slide 3

Slide 3 text

AsynCore

Slide 4

Slide 4 text

@oh_duran

Slide 5

Slide 5 text

Codename Tulip Alvaro Duran 
 Senior Software Engineer 
 Kiwi.com The Making of Async

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Device Latency in CPU cycles L1 Cache 3 L2 Cache 14 RAM 250 DISK 41,000,000 NETWORK 240,000,000 Dahl, Ryan. Introduction to Node.js @oh_duran

Slide 8

Slide 8 text

Device Latency in CPU cycles L1 Cache 3 3 seconds L2 Cache 14 14 seconds RAM 250 250 seconds DISK 41,000,000 1.3 years NETWORK 240,000,000 7.6 years Dahl, Ryan. Introduction to Node.js @oh_duran

Slide 9

Slide 9 text

Non-blocking Blocking @oh_duran

Slide 10

Slide 10 text

Non-blocking Blocking @oh_duran

Slide 11

Slide 11 text

open("f i le", "r") ; line = f.readline() f = @oh_duran

Slide 12

Slide 12 text

open("f i le", "r") line = f.readline() def foo() : f.close() return line f = @oh_duran

Slide 13

Slide 13 text

try: line = f.readline() def foo() : f.close() return line open("f i le", "r") f i nally: f = @oh_duran

Slide 14

Slide 14 text

with line = f.readline() def foo() : return line open("f i le", "r") as f: @oh_duran

Slide 15

Slide 15 text

goto

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

@oh_duran

Slide 19

Slide 19 text

@oh_duran

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Run Run Run Run Trap Trap Trap OS Executes @oh_duran

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

Nystrom, Bob. What Color is Your Function? Independent SwitchableCallstacks @oh_duran Coroutines

Slide 25

Slide 25 text

def f i bonacci() : a, b = 0, 1 while True: yield b a, b = b, a + b Schemenauer, Neil; Peters, Tim; Lie Hetland, Magnus. PEP 255 - Simple Generators. @oh_duran

Slide 26

Slide 26 text

def averager() : total = 0.0 count = 0 
 average = None while True: term = yield average total += term count += 1 average = total / count Ramalho, Luciano. Fluent Python. O'Reilly 2015 @oh_duran

Slide 27

Slide 27 text

term = yield average sent into the generator total += term count += 1 average = total / count def averager() : total = 0.0 count = 0 
 average = None while True: yielded to the caller @oh_duran

Slide 28

Slide 28 text

def averager() : while True: results[key] = yield averager() main() @oh_duran

Slide 29

Slide 29 text

def averager() : while True:

Slide 30

Slide 30 text

def averager() : total = 0.0 count = 0 
 average = None while True: term = yield average total += term count += 1 average = total / count @coroutine primes the generator flags the generator @oh_duran

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

Confusing Subtle Bugs Limiting @oh_duran

Slide 33

Slide 33 text

Adding a new keyword 
 is a lot harder than 
 adding new syntax 
 composed of existing keywords. —Guido The Di ff erence between Yield and Yield From. Python Tulip Google Groups @oh_duran

Slide 34

Slide 34 text

Meh. Just deal with it. —Guido The Di ff erence between Yield and Yield From. Python Tulip Google Groups @oh_duran

Slide 35

Slide 35 text

AsyncIO (Interoperable Layer) @oh_duran

Slide 36

Slide 36 text

Async/Await (API) @oh_duran

Slide 37

Slide 37 text

async def handler(client) : . . . data = await client.recv(10000) @coroutine def read(f i leno, maxbytes) : yield from ('read', f i leno, maxbytes) yield def run(coro, value) : try: trap = coro.send(value) except StopIteration: return e.value Sync Space Async Space @oh_duran

Slide 38

Slide 38 text

TRAP Kernel Space User Space @oh_duran

Slide 39

Slide 39 text

@oh_duran vole.wtf/coder - serial - killer - quiz/

Slide 40

Slide 40 text

@oh_duran

Slide 41

Slide 41 text

@oh_duran

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

[email protected] @oh_duran linkedin.com/in/alvaroduranbarata psst, my team at Kiwi.com is hiring! 
 Come see me after the Q&A