Re: [Python-ideas] Submitting a job to an asyncio event loop
I did remove it, because the feature has been implemented after the discussion:
https://docs.python.org/3/library/asyncio-task.html?highlight=run_coroutine#...
https://docs.python.org/3/library/asyncio-dev.html#asyncio-multithreading
https://github.com/python/asyncio/pull/273
2016-06-27 22:53 GMT+02:00 David Ford
Vincent, your github repo referenced here is 404. did you rename/move it?
On Saturday, September 26, 2015 at 2:29:43 PM UTC, Vincent Michel wrote:
Hi,
I noticed there is currently no standard solution to submit a job from a thread to an asyncio event loop.
Here's what the asyncio documentation says about concurrency and multithreading:
To schedule a callback from a different thread, the BaseEventLoop.call_soon_threadsafe() method should be used. Example to schedule a coroutine from a different thread: loop.call_soon_threadsafe(asyncio.async, coro_func())
The issue with this method is the loss of the coroutine result.
One way to deal with this issue is to connect the asyncio.Future returned by async (or ensure_future) to a concurrent.futures.Future. It is then possible to use a subclass of concurrent.futures.Executor to submit a callback to an asyncio event loop. Such an executor can also be used to set up communication between two event loops using run_in_executor.
I posted an implementation called LoopExecutor on GitHub: https://github.com/vxgmichel/asyncio-loopexecutor The repo contains the loopexecutor module along with tests for several use cases. The README describes the whole thing (context, examples, issues, implementation).
[...]
participants (1)
-
Vincent Michel