Asynchronous programming

Paul Rubin no.email at nospam.invalid
Fri Aug 12 21:31:44 EDT 2016


Steven D'Aprano <steve+python at pearwood.info> writes:
>>         await asyncio.sleep(0.2)  # pretend to do some real work
> That is *awesome*. Thank you for the example!

Keep in mind that the above basically takes the task off the list of
runnables for 0.2 seconds, so it sits doing nothing and doesn't
interfere with other tasks running.  In the case where you're doing
actual computation, you want to yield (await) much more often than 0.2
sec, so other tasks can stay responsive.  This is cooperative
multitasking, where each task has to be nice to the others, in contrast
with preemptive multitasking where the task switches happen behind the
scenes.



More information about the Python-list mailing list