Author yselivanov
Recipients aeros, asvetlov, primal, yselivanov
Date 2019-11-01.21:38:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1572644323.03.0.953214640452.issue32309@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-11-01 21:38:43yselivanovsetrecipients: + yselivanov, asvetlov, primal, aeros
2019-11-01 21:38:43yselivanovsetmessageid: <1572644323.03.0.953214640452.issue32309@roundup.psfhosted.org>
2019-11-01 21:38:43yselivanovlinkissue32309 messages
2019-11-01 21:38:42yselivanovcreate