temporalio.activity

Class ActivityCancellationDetails Provides the reasons for the activity's cancellation. Cancellation details are set once and do not change once set.
Class Info Information about the running activity.
Class LoggerAdapter Adapter that adds details to the log about the running activity.
Function cancellation_details Cancellation details of the current activity, if any. Once set, cancellation details do not change.
Function client Return a Temporal Client for use in the current 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 metric_meter Get the metric meter for the current activity.
Function payload_converter Get the payload converter for the current activity.
Function raise_complete_async Raise an error that says the activity will be completed asynchronously.
Function shield_thread_cancel_exception Context manager for synchronous multithreaded activities to delay cancellation exceptions.
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 _ActivityCancellationDetailsHolder Undocumented
Class _Context Undocumented
Class _Definition Undocumented
Exception _CompleteAsyncError Undocumented
Variable _current_context Undocumented

Cancellation details of the current activity, if any. Once set, cancellation details do not change.

Return a Temporal Client for use in the current activity.

The client is only available in async def activities.

In tests it is not available automatically, but you can pass a client when creating a temporalio.testing.ActivityEnvironment.

Decorator for activity functions.

Activities can be async or non-async.

Parameters
fn:CallableType | NoneThe function to decorate.
name:str | NoneName to use for the activity. Defaults to function __name__. This cannot be set if dynamic is set.
no_thread_cancel_exception:boolIf set to true, an exception will not be raised in synchronous, threaded activities upon cancellation.
dynamic:boolIf true, this activity will be dynamic. Dynamic activities have to accept a single 'Sequence[RawValue]' parameter. This cannot be set to true if name is present.

Send a heartbeat for the current activity.

Whether the current code is inside an activity.

Returns
boolTrue if in an activity, False otherwise.

Current activity's info.

Returns
InfoInfo for the currently running activity.

Whether a cancellation was ever requested on this activity.

Returns
boolTrue if the activity has had a cancellation request, False otherwise.

Whether shutdown has been invoked on the worker.

Returns
boolTrue if shutdown has been called on the worker, False otherwise.

Get the metric meter for the current activity.

Warning

This is only available in async or synchronous threaded activities. An error is raised on non-thread-based sync activities when trying to access this.

Raises
RuntimeErrorWhen not in an activity or in a non-thread-based synchronous activity.

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

Context manager for synchronous multithreaded activities to delay cancellation exceptions.

By default, synchronous multithreaded activities have an exception thrown inside when cancellation occurs. Code within a "with" block of this context manager will delay that throwing until the end. Even if the block returns a value or throws its own exception, if a cancellation exception is pending, it is thrown instead. Therefore users are encouraged to not throw out of this block and can surround this with a try/except if they wish to catch a cancellation.

This properly supports nested calls and will only throw after the last one.

This just runs the blocks with no extra effects for async activities or synchronous multiprocess/other activities.

Asynchronously wait for this activity to get a cancellation request.

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

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

Asynchronously wait for shutdown to be called on the worker.

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

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

Parameters
timeout:timedelta | float | NoneMax amount of time to wait for shutdown to be called on the worker.

Logger that will have contextual activity details embedded.