aioplus.CallerThreadExecutor

class aioplus.CallerThreadExecutor(max_workers=None, thread_name_prefix='', initializer=None, initargs=())

An executor that uses the caller thread.

Examples

>>> executor = CallerThreadExecutor()
>>> loop = asyncio.new_event_loop()
>>> loop.set_default_executor(executor)
Parameters:
  • max_workers (int | None) –

  • thread_name_prefix (str) –

  • initializer (Callable[[...], Any] | None) –

  • initargs (tuple[Any, ...]) –

__enter__()[source]

Enter the context.

Returns:

Self.

Return type:

Self

__exit__(exc_type, exc_val, exc_tb)[source]

Shutdown the executor and wait for all futures to complete.

Parameters:
  • exc_type (type[BaseException] | None) – The exception type.

  • exc_val (BaseException | None) – The exception instance.

  • exc_tb (TracebackType | None) – The traceback object.

Returns:

Reraise exceptions.

Return type:

Literal[False]

__init__(max_workers=None, thread_name_prefix='', initializer=None, initargs=())[source]

Initialize the object.

Parameters:
  • max_workers (int, optional) – This parameter does not affect the behavior of the executor.

  • thread_name_prefix (str) – This parameter does not affect the behavior of the executor.

  • initializer (Callable[..., Any], optional) – This parameter does not affect the behavior of the executor.

  • initargs (tuple[Any, ...]) – This parameter does not affect the behavior of the executor.

Return type:

None

Notes

  • Parameters are never used and serve as placeholders to comply with the interface of concurrent.futures.ThreadPoolExecutor (Liskov Substitution Principle).

map(fn, *iterables, timeout=None, chunksize=1, buffersize=None)[source]

Map the callable to the iterables.

Parameters:
  • fn (Callable[P, R]) – Callable.

  • *iterables (Iterable[P]) – Iterables to map the callable to.

  • timeout (float, optional) – Timeout.

  • chunksize (int) – This parameter does not affect the behavior of the executor.

  • buffersize (int, optional) – This parameter does not affect the behavior of the executor.

Returns:

Iterator.

Return type:

Iterator[R]

Notes

  • This method submits lazily to avoid blocking the caller thread on infinite iterators;

  • If timeout is specified, then TimeoutError is always raised. The executor uses the caller thread, so there is no way to enforce the timeout.

shutdown(wait=True, *, cancel_futures=False)[source]

Signal the executor that it should free resources.

Parameters:
  • wait (bool) – Waiting for futures.

  • cancel_futures (bool) – This parameter does not affect the behavior of the executor.

Return type:

None

Notes

  • If wait is True then this method will not return until all the pending futures are done executing and the resources associated with the executor have been freed. If wait is False then this method will return immediately and the resources associated with the executor will be freed when all pending futures are done executing.

submit(fn, /, *args, **kwargs)[source]

Schedules the callable, fn, to be executed.

Parameters:
  • fn (Callable[P, R]) – Callable.

  • *args (P.args) – Positional arguments.

  • **kwargs (P.kwargs) – Keyword arguments.

Returns:

Future.

Return type:

Future[R]

Notes

  • Submitted tasks are executed immediately.