asyncio.to_process function, similar to asyncio.to_thread function

Hello all, I suppose asyncio.to_thread uses concurrent.futures.ThreadPoolExecutor under the hood, so it saves us from getting the running event loop and calling the loop.run_in_executor function . Why don’t we have a similar function for the ProcessPoolExecutor, e.g. asyncio.to_process? Abdulla

On Sun, Jan 3, 2021 at 6:44 PM Abdulla Al Kathiri <alkathiri.abdulla@gmail.com> wrote:
I suppose asyncio.to_thread uses concurrent.futures.ThreadPoolExecutor under the hood, so it saves us from getting the running event loop and calling the loop.run_in_executor function . Why don’t we have a similar function for the ProcessPoolExecutor, e.g. asyncio.to_process?
asyncio.to_thread doesn't use ThreadPoolExecutor. Since thread is cheap, the function create a new thread every time. On the other hand, process is not cheap. That's why the only thread has convenient way to run function in. Regards, -- Inada Naoki <songofacandy@gmail.com>

On Sun, Jan 3, 2021 at 6:44 PM Abdulla Al Kathiri <alkathiri.abdulla@gmail.com> wrote:
I suppose asyncio.to_thread uses concurrent.futures.ThreadPoolExecutor under the hood, so it saves us from getting the running event loop and calling the loop.run_in_executor function . Why don’t we have a similar function for the ProcessPoolExecutor, e.g. asyncio.to_process?
asyncio.to_thread doesn't use ThreadPoolExecutor. Since thread is cheap, the function create a new thread every time. On the other hand, process is not cheap. That's why the only thread has convenient way to run function in. Regards, -- Inada Naoki <songofacandy@gmail.com>
participants (2)
-
Abdulla Al Kathiri
-
Inada Naoki