Re:Show HN: Bringing multithreading to Python's async event ...
by d0mine on Thursday October 03, 2024 @05:39PM
(#41735320)
run_in_executor that can be spelled as asyncio.to_thread() won't help utilizing cpu for pure Python code. It may help with blocking I/O, or cpu-heavy C extensions that release GIL. Otherwise, you have to utilize different processes to take full advantage of cpus (there are also subinterpreters (same process, separate GILs) but that exotic).
[ Parent
| on HN ]
Re:Show HN: Bringing multithreading to Python's async event ...
by noident on Sunday October 06, 2024 @03:24PM
(#41759506)
>run_in_executor that can be spelled as asyncio.to_thread() won't help utilizing cpu for pure Python code
That isn't true. If you use a ProcessPoolExecutor as the target instead of the default executor, you will use multiple processes in pure Python code.
Re:Show HN: Bringing multithreading to Python's async event ...
by d0mine on Monday October 07, 2024 @03:15PM
(#41769848)
the default executor must be ThreadPoolExecutor. But you are right you can pass ProcessPoolExecutor too.
https://docs.python.org/3/library/asyncio-eventloop.html#asy...