aiothreading documentation

class aiothreading.core.Thread(group: None = None, target: Callable[[...], Coroutine[Any, Any, R]] | None = None, name: str | None = None, args: Sequence[Any] | None = None, kwargs: dict[str, Any] | None = None, *, daemon: bool | None = None, initializer: Callable[[...], Any] | None = None, initargs: Sequence[Any] = (), loop_initializer: Callable[[...], AbstractEventLoop] | None = None, thread_target: Callable[[...], Any] | None = None)

Execute a coroutine on a spreate thread

property daemon: bool

Should child thread be daemon.

property ident: int | None

Thread ID of child, or None if not started.

is_alive() bool

Is child thread running.

is_started() bool

Is child thread started.

is_stopped() bool

Is child thread stopped.

async join(timeout: float | None = None) Any

Wait for the process to finish execution without blocking the main thread.

property name: str

Child thread name.

property native_id: int | None

Native thread ID of child, or None if not started.

static run_async(unit: Unit[R], *, _set_complete_event: bool = True) R | Literal[StopEnum.PREMATURE_STOP]

Initializes the child thread and event loop, then executes the coroutine.

start() None

Start the child thread.

terminate() None

Terminates child thread from running

class aiothreading.core.Worker(group: None = None, target: Callable[[...], Coroutine[Any, Any, R]] | None = None, name: str | None = None, args: Sequence[Any] | None = None, kwargs: dict[str, Any] | None = None, *, daemon: bool | None = None, initializer: Callable[[...], Any] | None = None, initargs: Sequence[Any] = (), loop_initializer: Callable[[...], AbstractEventLoop] | None = None)
property exception: BaseException | None

Easy access to the exception from the coroutine.

async join(timeout: float | None = None) R

Wait for the worker to finish, and return the final result.

property result: R

Easy access to the resulting value from the coroutine.

static run_async(unit: Unit[R], *, _set_complete_event: bool = True) R | Literal[StopEnum.PREMATURE_STOP]

Initializes the child thread and event loop, then executes the coroutine.

async aiothreading.core.not_implemented(*args: Any, **kwargs: Any) NoReturn

Default function to call when none given.

class aiothreading.pool.ThreadPool(threads: int | None = None, initializer: Callable[[...], Any] | None = None, initargs: Sequence[Any] = (), childconcurrency: int = 0, loop_initializer: Callable[[...], AbstractEventLoop] | None = None, exception_handler: Callable[[BaseException], None] | None = None)

Execute coroutines on a pool of threads.

close() None

Close the pool to new visitors.

async join() None

Waits for the pool to be finished gracefully.

map(func: Callable[[T], Coroutine[Any, Any, R]], iterable: Sequence[T] | Iterable[T]) ThreadPoolResult[R]

Run a coroutine once for each item in the iterable.

starmap(func: Callable[[...], Coroutine[Any, Any, R]], iterable: Sequence[Sequence[T] | Iterable[T]]) ThreadPoolResult[R]

Run a coroutine once for each sequence of items in the iterable.

submit(func: Callable[[...], Coroutine[Any, Any, R]], /, *args: Any, **kwargs: Any) Future[R]

Run a single coroutine on the pool.

terminate() None

No running by the pool!

class aiothreading.pool.ThreadPoolResult(futures: Sequence[Future[_T]])

Asynchronous proxy for map/starmap results. Can be awaited or iterated over by using async for.

async results() Sequence[_T]

Wait for all results and return them as a sequence

async results_generator() AsyncIterator[_T]

Return results one-by-one as they are ready

class aiothreading.pool.ThreadPoolWorker(tx: SimpleQueue[tuple[Callable[[...], Coroutine[Any, Any, Any]], Sequence[Any], dict[str, Any], Future[Any]] | None], concurrency: int = 0, *, exception_handler: Callable[[BaseException], None] | None = None, **kwargs: Any)

Individual worker thread for the async pool.

async run() None

Pick up work, schedule work, repeat.