On 8/10/2016 11:53 PM, Steven D'Aprano wrote:
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?

You might be able to glean something from the succession of files I uploaded to
https://bugs.python.org/issue27546
Integrate tkinter and asyncio (and async)

I started with just mixing tk and asyncio callbacks. After some struggle with similar question as you ask above, I ended up with more or less callback free code using async def and async for. Once I got over the hump, I rather like it.

--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to