Asynchronous programming

Steven D'Aprano steve+python at pearwood.info
Wed Aug 10 23:53:31 EDT 2016


The latest versions of Python are introducing new keywords for asynchronous
programming, async and await. See PEP 492:

https://www.python.org/dev/peps/pep-0492/

Is there a good beginner's tutorial introducing the basics of asynchronous
programming? Starting with, why and where would you use it?

I've read "What colour is your function" and it isn't quite jelling for me.

http://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/


How is this the same as, or different from, event-based programming? I'm
familiar with programming in an event-based language where the interpreter
itself provides an event loop and dispatches messages to your objects:

- I define objects such as buttons, text fields, etc., and give them methods
("handlers") which handle certain messages such as "mouseUp", etc.;

- the interpreter runs in a loop, firing off messages in response to the
user's actions;

- there's a message passing hierarchy, whereby messages are first received
by (let's say) the button the user clicked on, if not handled by a mouseUp
method it is passed on to the next object in the hierarchy (say, the
window), and then finally to the interpreter itself, at which point it
either ignores the message or raises an exception.


If I'm using async and await in Python, where's the event loop? What are the
messages, and where are they sent? Or am I on the wrong track altogether?




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list