Yury Selivanov <yseliva...@gmail.com> added the comment:

Few thoughts:

1. I like the idea of having a context manager to create a thread pool. It 
should be initialized in a top-level coroutine and the passed down to other 
code, as in:

  async def main():
    async with asyncio.ThreadPool(concurrency=10) as pool:
      await something(pool)
      await something_else(pool)

      await pool.run(callable, *args)

  asyncio.run(main())

2. It should be the "async with".

3. We should not reuse the default executor. The default executor is used for 
things like DNS resolution.  We don't want network activity to pause just 
because some task offloaded some blocking computation to its pool.

4. I think it's OK to initialize the thread pool in `ThreadPool.__init__`.  
`ThreadPool.__aenter__` would simply return `self` then.

5. `await ThreadPool.aclose()` would close the loop gracefully (awaiting for 
all submitted and still running callables) in cases when people use the 
threadpool without 'async with'.

6. I think we should aim for shipping a replacement for `loop.run_in_executor` 
in 3.9.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32309>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to