Asynchronous programming

Ethan Furman ethan at stoneleaf.us
Sat Aug 13 15:29:20 EDT 2016


On 08/11/2016 07:14 AM, Steven D'Aprano wrote:
> On Thu, 11 Aug 2016 03:06 pm, Paul Rubin wrote:
>
>> The basic characteristic of asynchronous programming is that it involves
>> changing all your usual blocking i/o calls to non-blocking ones, so your
>> program can keep running as soon as your request is started.
>
> That's the bit that confuses me. I understand about parallel processing, but
> that's not what this is about.
>
> Say I want to download data from a network, and it will take a long time. If
> I can do the read in parallel to something else, that makes sense:
>
>    begin downloading in another thread/process
>    make a coffee
>    process download
>
>
> But what's the point in doing it asynchronously if I have to just wait for
> it to complete?
>
>    begin downloading in an async thread
>    twiddle thumbs, doing nothing
>    process download

async, threads, multiprocessing, etc., all only make sense if you have more than one thing to do.  The advantage of the new async stuff is it allows us to write in a synchronous manner (making async calls instead of blocking calls) and the underlying framework takes care of the hassle of using threads or multiprocessing or whatever.

--
~Ethan~



More information about the Python-list mailing list