Kyle Stanley <aeros...@gmail.com> added the comment:

> 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.

----------
nosy: +aeros

_______________________________________
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