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:

The executor iteself.

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:

This method always returns False.

Return type:

Literal[False]

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

Initialize the object.

Parameters:
  • max_workers (int or None) – 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] or None) – 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 function to the iterables.

Parameters:
  • fn (Callable[P, R]) – The function to map.

  • *iterables (Iterable[P]) – The iterables to map the function to.

  • timeout (float | None) – The timeout for the operation.

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

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

Returns:

An iterator over the results.

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) – 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.

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

Returns:

This method does not return a value.

Return type:

None

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

Schedules the callable, fn, to be executed.

Parameters:
  • fn (Callable[P, R]) – The callable to be executed.

  • *args (P.args) – Positional arguments to pass to the callable.

  • **kwargs (P.kwargs) – Keyword arguments to pass to the callable.

Returns:

A future representing the execution of the callable.

Return type:

Future[R]

Notes

  • Submitted tasks are executed immediately.