Author aeros
Recipients aeros, asvetlov, yselivanov
Date 2019-10-31.21:46:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1572558408.76.0.295752768805.issue32309@roundup.psfhosted.org>
In-reply-to
Content
> I don't like the low-level API of run_in_executor.  "executor" being the first argument, the inability to pass **kwargs, etc.

> I mean it's great that we can use 'concurrent.futures' in asyncio, but having native asyncio pools implementation would be way more convenient to the users.

I agree that there's an issue with this, but I think for the high level API it can be an asynchronous context manager that makes use of concurrent.futures.ThreadPoolExecutor, since that one seems to fit the majority of asyncio use cases. If users want to utilize concurrent.futures.ProcessPoolExecutor or a customized one, they can use loop.run_in_executor() instead. 

Unless there's something I'm missing with regards to concurrent.futures.ThreadPoolExecutor that specifically makes it less usable. Can't asyncio.ThreadPool make use of concurrent.futures.ThreadPoolExecutor in the internal details while providing a better API?

> I'd expect to see a more high-level API, perhaps the one that supports 'async with':

> asyncio.ThreadPool() sounds great. Maybe thread group can provide better api.

I'd be willing to work on implementing the asyncio.ThreadPool API as Yury described it.

> But for Python 3.8 adding `run_in_executor` top-level function looks the only easy and obvious way to help people getting rid of explicit loop usage.

I can see your point Andrew, but I think that if we implement asyncio.run_in_executor() and then later add asyncio.ThreadPool(), it's going to be against "one obvious way" and we'll end up adding two high-level functions for the same purpose. This principle can't always be adhered to, but I think we should try to when it's possible. 

Personally, I think the API for asyncio.ThreadPool would be much more robust, so it seems worthwhile to try implementing this one first. If there are a number of unforeseen complications, asyncio.run_in_executor() might still be a decent fallback.
History
Date User Action Args
2019-10-31 21:46:48aerossetrecipients: + aeros, asvetlov, yselivanov
2019-10-31 21:46:48aerossetmessageid: <1572558408.76.0.295752768805.issue32309@roundup.psfhosted.org>
2019-10-31 21:46:48aeroslinkissue32309 messages
2019-10-31 21:46:48aeroscreate