asyncx.run_coroutine_in_thread
- asyncx.run_coroutine_in_thread(coro, *, loop=None)[source]
Submit a coroutine in a new thread and waits for its completion in a given
loop.Example
>>> async def _get_ident() -> int: ... return threading.get_ident() ... >>> main, sub = await asyncio.gather( ... _get_ident(), ... asyncx.run_coroutine_in_thread(_get_ident()), ... ) >>> main == sub False
- Arg:
coro: A coroutine to run in a new thread. loop: An event loop to wait for the completion of
coro.
- Returns
A
asyncio.Futureobject that returns the execution result of a given coroutine.- Parameters
coro (Coroutine[Any, Any, TReturn]) –
loop (Optional[asyncio.AbstractEventLoop]) –
- Return type
asyncio.Future[TReturn]