Asynchronous processing is more efficient -- surely not?

Terry Reedy tjreedy at udel.edu
Wed Apr 4 22:52:24 EDT 2018


On 4/4/2018 3:27 AM, Steven D'Aprano wrote:
> So, I'm, still trying to wrap my brain around async processing, and I
> started reading this tutorial:
> 
> http://stackabuse.com/python-async-await-tutorial/
> 
> and the very first paragraph broke my brain.
> 
> "Asynchronous programming has been gaining a lot of traction in the past
> few years, and for good reason. Although it can be more difficult than
> the traditional linear style, it is also much more efficient."

For multiple byte streams, async is more efficient in terms of bytes 
transmitted per unit time than transmitting each stream one at a time 
until completed.  Indeed, multiple infinite streams can be interleaved.

[snip]

> But honestly, from everything I've seen, outside of browser apps (and I'm
> not even sure about them), async processing looks to me like the wrong
> solution to, well, everything.

The async module is event-driven programming applied to transmission 
between cpu and disk, other processes, or other systems.  The tkinter 
module does event-driven programming applied to transmission between cpu 
and humans (key and mouse input, screen output).  Both tkinter and async 
have time events.  One can even drive tkinter GUIs with the async loop 
instead of the tk loop.  (And this allows use of 'async' and 'await' 
with tkinter programs.)  Event-loop GUI applications and many games are 
'asynchronous processing' in the generic sense.  But these are a few 
decades old, not just a few years old.

  It combines the worst of sequential and
> parallel processing with the benefits of neither. It's like cooperative
> multi-tasking, only without the actual multi-tasking

I am not sure what you mean by 'multi-tasking' here.

> and even less
> convenience. Its harder to use than threading or multiprocessing, but

I can't imaging doing a gui with either, but maybe async is less 
convenient to use than async.

> without their ability to run in parallel. It lacks the isolation of
> multiprocessing, and the preemptive task swapping of threads/processes.
> 
> Its as hard to wrap your brain around as parallel processing in general,
> but with even worse performance than sequential processing.

Do you have trouble with interactive games and GUIs?  The async module 
is the same idea applied (mainly) to socket events.  Indeed, key, mouse, 
and display events can be transmitted through sockets as byte streams. 
(I believe that this is how unix X-servers operate).

> Am I totally wrong?

-- 
Terry Jan Reedy




More information about the Python-list mailing list