On Fri, 14 Jun 2019 at 12:00, Nikita Melentev <multisosnoo...@gmail.com>
wrote:

> > The problem is that the snippet itself is not very helpful.
>
> Explain please.
>
> The good thing is that, if this snippet will be somewhere (asyncio or
> docs), then user will not decide by its own about "what is a long running
> task", because good default value will be there. This also reduce time to
> fix such cases, sometimes when you write code you don't expect huge data in
> your loops, but if your case allows to "interrupt" your loop by context
> switch, then you can just use wrapper and forget about this.
>

The problem is that there is no good universal default for when to yield.
Yielding too frequently will make the program run slower, yielding too
infrequently will cause latency in coroutine switching (the program you try
to solve).

The problem gets more complicated with nested loops.  Do you yield in all
loop nested levels?  If not, only the outer one, only the inner one?

That said, your code snippet is a nice tool to have in the toolbox.  I've
written something similar but not as complete: my version just yielded
after N iterations, your version also allows yielding after X seconds,
which is nice.

I almost wish such functionality could be built into Python.  But I'm not
sure it can be done without performance penalty.


_______________________________________________
> 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/Y6BW6USOZISKGHBTVHGDBBQJCO2MSW33/
> 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/E6UFX2KN4RGFA4WUKF2Q4UAGSQMHOYEN/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to