Topics of Interest (Async) (original) (raw)

David Beazley (@dabeaz)
Nove...")
Brasil

I'm honored to be here from Chicago
")

love our BBQ
... even in -25C
")

"asyncio is the future of Python."
")

If you need to write a program to ma...")
10000 concurrent network connections, then asyncio is your problem.

")

public static async void Copy...")
destination) { byte[] buffer = new byte[0x1000]; int numRead; while((numRead = await source.ReadAsync(buffer, 0, buffer.Length)) > 0) { await destination.WriteAsync(buffer, 0, numRead); } } Source: http://blogs.msdn.com/b/dotnet/archive/2012/04/03/ async-in-4-5-worth-the-await.aspx

async function chainAnimations...")
null; try { for(const anim of animations) { ret = await anim(elem); } } catch(e) { /* ignore and keep going */ } return ret; } Source: http://tc39.github.io/ecmascript-asyncawait/

import "dart:html";
main() async {
var con...")
var running = true; // Set false to stop game. while (running) { var time = await window.animationFrame; context.clearRect(0, 0, 500, 500); context.fillRect(time % 450, 20, 50, 50); } } Source: https://www.dartlang.org/articles/await-async/

val futureDOY: Future[Response] =
WS.url(...")
WS.url("http://api.days-left/today").get val respFut = async { val dayOfYear = await(futureDOY).body val daysLeft = await(futureDaysLeft).body Ok(s"$dayOfYear: $daysLeft days left!") } Source: http://docs.scala-lang.org/sips/pending/async.html

ASYN FUNCTION NGCD(NA, NB)
IA = NA
IB =...")
NB 1 IF (IB.NE.0) THEN ITEMP = IA IA = IB IB = AWAI MOD(ITEMP, IB) GOTO 1 END IF NGCD = IA RETURN END

ASYN FUNCTION NGCD(NA, NB)
IA = NA
IB =...")
NB 1 IF (IB.NE.0) THEN ITEMP = IA IA = IB IB = AWAI MOD(ITEMP, IB) GOTO 1 END IF NGCD = IA RETURN END (actually I'm not so sure about Fortran)

")

")

"Async/await is amazing, ...")
working with asynchronous code in Javascript" - Thomas Hunter

")

")

")

")

")

class Future:
...
def __iter...")
self.done(): yield self return self.result()

"If we don't fix this, we will all go insa...")
insane."

")

(Perfectly)
")

")

• I get the big picture (concurrency...")
• Is it a replacement for Tornado/Twisted? • Is it a layer that everyone should use? • Is it an reference implementation of an API? • Also: How do I teach this?

Threads
Polling
def handle_echo(cl...")
client.recv(10000) if not data: break client.sendall(data) while True: r, w, _ = select(readers, writers, [] for s in r: handle_read(s) for s in w: handle_write(s)

Threads
Polling
Callbacks
")

Threads
Polling
Callbacks Futures,...")

Threads
Polling
Callbacks Futures,...")

Threads
Polling
Callbacks Futures,...")
stackless

Threads
Polling
Callbacks Futures,...")
"Green threads?" stackless

Threads
Polling
Callbacks Futures,...")
Coroutines "Green threads?" stackless

Threads
Polling
Callbacks Futures,...")
Coroutines yield from "Green threads?" stackless

Threads
Polling
Callbacks Futures,...")
Coroutines yield from asyncio "Green threads?" stackless

Threads
Polling
Callbacks Futures,...")
Coroutines yield from asyncio async/await "Green threads?" stackless

• Think about everything goin...")
It is a complicated problem • It is an important problem • But, it has a complicated history • Each part requires deep study • A lot of smart people have worked on it

I DO NOT WANT TO THINK ABOUT
CALLBACKS,...")
TASKS, COROUTINES, TRANSPORTS, EVENT LOOPS, ETC.

")

THIS
")

Polling
Callbacks Futures,
Deferreds
Ge...")
from asyncio async/await Is There A Shortcut?

Threads
Polling
Callbacks ...")
async/await

Maybe THIS is the
async future
")

Maybe Python's async should be an inter...")
an implementation not a library not asyncio

")

• Can an async API exist independentl...")
async implementation? • Maybe • It seems that it should be possible • Especially if you embrace async/await

• Python has standardized ...")
• Database API

• The design of such an API is...")
interesting • What operations require "await"? • Consistency in the interface • Interconnections between parts • Can you isolate it from the runtime?

• APIs encourage experimentat...")
competition • And better interoperability • APIs are better than layers

")

• Special thanks:
• Yarko Tymciurak...")
PyCon Brasil Organizers • Twitter: @dabeaz • Questions!