On Sat, 15 Jun 2019 at 00:26, Greg Ewing <greg.ew...@canterbury.ac.nz>
wrote:

> Gustavo Carneiro wrote:
> > 1. If you don't yield in the for loop body, then you are blocking the
> > main loop for 1 second;
> >
> > 2. If you yield in every iteration, you solved the task switch latency
> > problem, but you make the entire program run much slower.
>
> It sounds to me like asyncio is the wrong tool for this job. You
> want a background task that can be preempted by a foreground task.
> That's what threads are for. Asyncio gives you non-preemptive
> task scheduling.
>

Perhaps.  But using threads is more complicated.  You have to worry about
the integrity of your data in the face of concurrent threads.  And if
inside your task you sometimes need to call async coroutine code, again you
need to be extra careful, you can't just call coroutines from threads
directly.

But I think you do have a point.  If a developer starts reaching for `await
asyncio.sleep(0)` too often, perhaps it is time to start considering
running that code in the default thread pool executor, whatever the cost
may be.


> --
> Greg
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/RLGF5NOLRXYGEOWTLT4N6KYAWRWXHI6J/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
Gustavo J. A. M. Carneiro
Gambit Research
"The universe is always one step beyond logic." -- Frank Herbert
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/ALN3KUJFODLKP7HZ3SZ3QOOMVT56UC6G/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to