[issue32309] Implement asyncio.create_task() and asyncio.run_in_executor shortcuts
New submission from Andrew Svetlov <andrew.svetlov@gmail.com>: loop.create_task() and loop.run_in_executor are present very often in user code. But they are require a loop instance, actual call looks like loop = asyncio.get_running_loop() loop.create_task(coro()) The proposal adds create_task(coro) and run_in_executor(executor, func, *args) shortcuts for this. ---------- assignee: docs@python components: Documentation, asyncio messages: 308238 nosy: asvetlov, docs@python, yselivanov priority: normal severity: normal status: open title: Implement asyncio.create_task() and asyncio.run_in_executor shortcuts versions: Python 3.7 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue32309> _______________________________________
Change by Andrew Svetlov <andrew.svetlov@gmail.com>: ---------- keywords: +patch pull_requests: +4736 stage: -> patch review _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue32309> _______________________________________
Yury Selivanov <yselivanov@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'd expect to see a more high-level API, perhaps the one that supports 'async with': async with asyncio.ThreadPool() as pool: f1 = pool.run(func1) f2 = pool.run(func2) r3 = await pool.run(func3) r1 = f1.result() r2 = f2.result() print(r1, r2, r3) 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. In any case, can we focus this issue on the "run_in_executor" API, and open a new one for "create_task"? ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue32309> _______________________________________
participants (2)
-
Andrew Svetlov -
Yury Selivanov