System utilities

Contents

System utilities#

System utilities support asynchronous and resource-managed applications.

The system module.

Contains tools and utilities for dealing with (async) disposables and cancellation tokens.

class AnonymousDisposable(action: Callable[[], None])#
dispose() → None#

Performs the task of cleaning up resources.

class AsyncAnonymousDisposable(action: Callable[[], Awaitable[None]])#
async dispose_async() → None#
class AsyncCompositeDisposable(*disposables: AsyncDisposable)#
async dispose_async() → None#
class AsyncDisposable#

The async disposable.

A disposable class with a context manager. Must implement the dispose_async method. Will dispose on exit.

static composite(*disposables: AsyncDisposable) → AsyncDisposable#
static create(action: Callable[[], Awaitable[None]]) → AsyncDisposable#
abstract async dispose_async() → None#
static empty() → AsyncDisposable#
class CancellationToken(cancelled: bool = True, source: CancellationTokenSource | None = None)#

CancellationToken class.

A CancellationToken enables cooperative cancellation between threads, thread pool work items, or Task objects. You create a cancellation token by instantiating a CancellationTokenSource object, which manages cancellation tokens retrieved from its CancellationTokenSource.Token property. You then pass the cancellation token to any number of threads, tasks, or operations that should receive notice of cancellation. The token cannot be used to initiate cancellation. When the owning object calls CancellationTokenSource.cancel, the is_cancellation_requested property on every copy of the cancellation token is set to true. The objects that receive the notification can respond in whatever manner is appropriate.

property can_be_canceled: bool#
property is_cancellation_requested: bool#
static none()#
register(callback: Callable[[], None]) → Disposable#
throw_if_cancellation_requested()#
class CancellationTokenSource#
cancel() → None#
static cancelled_source() → CancellationTokenSource#
dispose() → None#

Performs the task of cleaning up resources.

property is_cancellation_requested: bool#
register_internal(callback: Callable[[], None]) → Disposable#
property token: CancellationToken#
class Disposable#

The disposable class.

A disposable class with a context manager. Must implement the dispose method. Will dispose on exit.

static create(action: Callable[[], None])#

Create disposable.

Create disposable from action. Will call action when disposed.

abstract dispose() → None#
exception ObjectDisposedException#
exception OperationCanceledError#
class CancellationToken(cancelled: bool = True, source: CancellationTokenSource | None = None)#

CancellationToken class.

A CancellationToken enables cooperative cancellation between threads, thread pool work items, or Task objects. You create a cancellation token by instantiating a CancellationTokenSource object, which manages cancellation tokens retrieved from its CancellationTokenSource.Token property. You then pass the cancellation token to any number of threads, tasks, or operations that should receive notice of cancellation. The token cannot be used to initiate cancellation. When the owning object calls CancellationTokenSource.cancel, the is_cancellation_requested property on every copy of the cancellation token is set to true. The objects that receive the notification can respond in whatever manner is appropriate.

property can_be_canceled: bool#
property is_cancellation_requested: bool#
static none()#
register(callback: Callable[[], None]) → Disposable#
throw_if_cancellation_requested()#
class CancellationTokenSource#
cancel() → None#
static cancelled_source() → CancellationTokenSource#
dispose() → None#

Performs the task of cleaning up resources.

property is_cancellation_requested: bool#
register_internal(callback: Callable[[], None]) → Disposable#
property token: CancellationToken#
class AnonymousDisposable(action: Callable[[], None])#
dispose() → None#

Performs the task of cleaning up resources.

class AsyncAnonymousDisposable(action: Callable[[], Awaitable[None]])#
async dispose_async() → None#
class AsyncCompositeDisposable(*disposables: AsyncDisposable)#
async dispose_async() → None#
class AsyncDisposable#

The async disposable.

A disposable class with a context manager. Must implement the dispose_async method. Will dispose on exit.

static composite(*disposables: AsyncDisposable) → AsyncDisposable#
static create(action: Callable[[], Awaitable[None]]) → AsyncDisposable#
abstract async dispose_async() → None#
static empty() → AsyncDisposable#
class Disposable#

The disposable class.

A disposable class with a context manager. Must implement the dispose method. Will dispose on exit.

static create(action: Callable[[], None])#

Create disposable.

Create disposable from action. Will call action when disposed.

abstract dispose() → None#