The real problem is: you have a long-running synchronous loop (or
CPU-bound task in general).
The real solution is: run it inside a thread pool.
By explicit inserting context switches, you don't eliminate the
problem but hide it.
asyncio loop is still busy on handling your CPU-bound task, it
decreases the whole system response time.

Imagine you have 1000 tasks, each pauses the execution by 10ms at most.
The loop can be paused by 1000*10ms = 10 sec if all tasks decide to
switch at the same time.
You cannot control it, asyncio uses non-preemptible strategy for tasks
switching.
Preemtible strategy is called multi-threading and requires
participation with OS kernel. Period.

On Fri, Jun 14, 2019 at 6:27 PM Nikita Melentev
<multisosnoo...@gmail.com> wrote:
>
> Exactly our case!
> My position is same as njsmith (AFAIR) said somewhere about running file-io 
> in threads: yes, it is faster to write chunk directly from coroutine, than 
> write chunk from executor, but you guarantee that there will be no «freeze».
> _______________________________________________
> 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/TLYGM36EZQLH6BBNI55QMAYOM3IPWZWB/
> Code of Conduct: http://python.org/psf/codeofconduct/



-- 
Thanks,
Andrew Svetlov
_______________________________________________
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/V5H6G5WBM2QQC24OVRIWTXKMYO6VQ2W4/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to