asyncio bridge: AsyncioExecutor
¶
AsyncioExecutor transforms concurrent.futures
futures into
asyncio
futures.
- class more_executors.AsyncioExecutor(delegate, loop=None, logger=None, name='default')¶
An executor which delegates to another executor while converting returned futures into instances of
asyncio.Future
.Note that since this class produces
asyncio
rather thanconcurrent.futures
future objects, AsyncioExecutor instances themselves cannot be used as a delegate executor of other executor instances within this library.New in version 1.7.0.
- Parameters
delegate (Executor) – executor to which callables will be submitted
loop (AbstractEventLoop) –
asyncio event loop used to wrap futures; if omitted, the return value of
asyncio.get_event_loop()
is used.Note
Starting from Python 3.12,
asyncio.get_event_loop()
raises an exception if there is no current event loop, so it is necessary to either pass a loop explicitly or ensure there is a running loop prior to constructing this executor.logger (Logger) – a logger used for messages from this executor
name (str) – a name for this executor
Changed in version 2.7.0: Introduced
name
.
- classmethod Executors.with_asyncio(executor, loop=None, logger=None)¶
- Returns
a new executor which returns
asyncio.Future
instances rather thanconcurrent.futures.Future
instances, i.e. may be used with the await keyword and coroutines.- Return type
Note
Since the other executors from
Executors
class are designed for use withconcurrent.futures.Future
, if an executor is being configured using chained with_* methods, this must be the last method called.Note
Only usable for Python >= 3.5.
New in version 1.7.0.