Skip to main content

prefect.task_runs

Classes

TaskRunWaiter

A service used for waiting for a task run to finish. This service listens for task run events and provides a way to wait for a specific task run to finish. This is useful for waiting for a task run to finish before continuing execution. The service is a singleton and must be started before use. The service will automatically start when the first instance is created. A single websocket connection is used to listen for task run events. The service can be used to wait for a task run to finish by calling TaskRunWaiter.wait_for_task_run with the task run ID to wait for. The method will return when the task run has finished or the timeout has elapsed. The service will automatically stop when the Python process exits or when the global loop thread is stopped. Example:
Methods:

add_done_callback

Add a callback to be called when a task run finishes. Args:
  • task_run_id: The ID of the task run to wait for.
  • callback: The callback to call when the task run finishes.

instance

Get the singleton instance of TaskRunWaiter.

start

Start the TaskRunWaiter service.

stop

Stop the TaskRunWaiter service.

wait_for_task_run

Wait for a task run to finish and return its final state. Note this relies on a websocket connection to receive events from the server and will not work with an ephemeral server. Args:
  • task_run_id: The ID of the task run to wait for.
  • timeout: The maximum time to wait for the task run to finish. Defaults to None.
Returns:
  • The final state of the task run if available, None otherwise.