Benefits of asyncio
Paul Rubin
no.email at nospam.invalid
Mon Jun 2 16:45:39 EDT 2014
Marko Rauhamaa <marko at pacujo.net> writes:
> - Thread programming assumes each thread is waiting for precisely
> one external stimulus in any given state -- in practice, each
> state must be prepared to handle quite a few possible stimuli.
Eh? Threads typically have their own event loop dispatching various
kinds of stimuli.
> - Thread-safe programming is easy to explain but devilishly
> difficult to get right.
I keep hearing that but not encountering it. Yes there are classic
hazards from sharing mutable state between threads. However, it's
generally not too difficult to program in a style that avoids such
sharing. Have threads communicate by message passing with immutable
data in the messages, and things tend to work pretty straightforwardly.
> Asyncio makes the prototype somewhat cumbersome to write. However,
> once it is done, adding features, stimuli and states is a routine
> matter.
Having dealt with some node.js programs and the nest of callbacks they
morph into as the application gets more complicated, threads have their
advantages.
More information about the Python-list
mailing list