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

Codename Tulip: The Making Of Async

Codename Tulip: The Making Of Async

Software has been riding on immense hardware improvement over decades. This has delayed ways to build products that are more effective, because you could cheaply rent yet another machine on the cloud and call it a day.

But hardware isn't getting better at the pace it used to, and costs are spiraling out of control. Software must become better at managing resources. Do more with less.

How? We can look at ways in which real world businesses maximize their effectiveness. Look at Starbucks! They have cashiers accepting orders, and baristas delivering them. That isn't rocket science; it's concurrency.

Would you be surprised to learn that modern programming languages aren't built for concurrency? It's as if English didn't have a syntax for asking questions! Concurrency is very much around us in real life, but Python pretends that things always happen One Damned Thing After Another.

Not all hope is lost. A few years ago, asyncio was introduced into the standard library to reboot concurrent programming. However, we're still getting used to it. It's weird! There are many things that we need to learn, and double check, and test and ultimately fix.

But what if none of that was the case? What if what we were missing was not Yet Another Standard, This Time By Guido, but a syntax?

I like my programming languages to have a semantics for concurrency, the way I like my English with a semantics for questions. And you?

Álvaro Durán

September 22, 2023
Tweet

More Decks by Álvaro Durán

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. open("f i le", "r") line = f.readline() def foo() :

    f.close() return line f = @oh_duran
  4. try: line = f.readline() def foo() : f.close() return line

    open("f i le", "r") f i nally: f = @oh_duran
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. Meh. Just deal with it. —Guido The Di ff erence

    between Yield and Yield From. Python Tulip Google Groups @oh_duran
  11. 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