module documentation

Functions that can be called inside of activities.

Most of these functions use contextvars to obtain the current activity in context. This is already set before the start of the activity. Activities that make calls that do not automatically propagate the context, such as calls in another thread, should not use the calls herein unless the context is explicitly propagated.

Class Info Information about the running activity.
Class LoggerAdapter Adapter that adds details to the log about the running activity.
Function defn Decorator for activity functions.
Function heartbeat Send a heartbeat for the current activity.
Function in_activity Whether the current code is inside an activity.
Function info Current activity's info.
Function is_cancelled Whether a cancellation was ever requested on this activity.
Function is_worker_shutdown Whether shutdown has been invoked on the worker.
Function raise_complete_async Raise an error that says the activity will be completed asynchronously.
Async Function wait_for_cancelled Asynchronously wait for this activity to get a cancellation request.
Function wait_for_cancelled_sync Synchronously block while waiting for a cancellation request on this activity.
Async Function wait_for_worker_shutdown Asynchronously wait for shutdown to be called on the worker.
Function wait_for_worker_shutdown_sync Synchronously block while waiting for shutdown to be called on the worker.
Variable logger Logger that will have contextual activity details embedded.
Class _CompleteAsyncError Undocumented
Class _CompositeEvent Undocumented
Class _Context Undocumented
Class _Definition Undocumented
Variable _current_context Undocumented
@overload
def defn(fn: CallableType) -> CallableType:
@overload
def defn(*, name: str) -> Callable[[CallableType], CallableType]:

Decorator for activity functions.

Activities can be async or non-async.

Parameters
fn:Optional[CallableType]The function to decorate.
name:Optional[str]Name to use for the activity. Defaults to function __name__.
def heartbeat(*details: Any):

Send a heartbeat for the current activity.

Raises
RuntimeErrorWhen not in an activity.
def in_activity() -> bool:

Whether the current code is inside an activity.

Returns
boolTrue if in an activity, False otherwise.
def info() -> Info:

Current activity's info.

Returns
InfoInfo for the currently running activity.
Raises
RuntimeErrorWhen not in an activity.
def is_cancelled() -> bool:

Whether a cancellation was ever requested on this activity.

Returns
boolTrue if the activity has had a cancellation request, False otherwise.
Raises
RuntimeErrorWhen not in an activity.
def is_worker_shutdown() -> bool:

Whether shutdown has been invoked on the worker.

Returns
boolTrue if shutdown has been called on the worker, False otherwise.
Raises
RuntimeErrorWhen not in an activity.
def raise_complete_async() -> NoReturn:

Raise an error that says the activity will be completed asynchronously.

async def wait_for_cancelled():

Asynchronously wait for this activity to get a cancellation request.

Raises
RuntimeErrorWhen not in an async activity.
def wait_for_cancelled_sync(timeout: Optional[float] = None):

Synchronously block while waiting for a cancellation request on this activity.

This is essentially a wrapper around threading.Event.wait.

Parameters
timeout:Optional[float]Max amount of time to wait for cancellation.
Raises
RuntimeErrorWhen not in an activity.
async def wait_for_worker_shutdown():

Asynchronously wait for shutdown to be called on the worker.

Raises
RuntimeErrorWhen not in an async activity.
def wait_for_worker_shutdown_sync(timeout: Optional[float] = None):

Synchronously block while waiting for shutdown to be called on the worker.

This is essentially a wrapper around threading.Event.wait.

Parameters
timeout:Optional[float]Max amount of time to wait for shutdown to be called on the worker.
Raises
RuntimeErrorWhen not in an activity.
logger =

Logger that will have contextual activity details embedded.

_current_context: contextvars.ContextVar[_Context] =

Undocumented