Skip to main content

Managing Task Runs

Managing task executions (runs) in flyte-sdk involves using the Run and RunDetails classes to monitor progress, retrieve data, and control execution state.

Fetching and Listing Runs

You can retrieve a specific run by its name or list all runs within the configured project and domain.

from flyte.remote import Run

# Fetch a specific run by name
run = Run.get(name="f7a2b3c4d5e6f7g8")
print(f"Run {run.name} is currently in phase: {run.phase}")

# List the 10 most recent runs
for r in Run.listall(limit=10, sort_by=("created_at", "desc")):
print(f"ID: {r.name} | Phase: {r.phase}")

The Run.listall method returns an AsyncIterator (which is synchronized for standard usage via @syncify) and supports filtering and sorting. By default, it sorts by created_at in ascending order.

Monitoring Execution Progress

To block execution until a run reaches a terminal state (Success, Failure, or Aborted), use the wait method. This provides a rich progress panel in the terminal by default.

from flyte.remote import Run

run = Run.get(name="f7a2b3c4d5e6f7g8")

# Wait for the run to finish (terminal state)
run.wait()

# Wait only until the run starts executing
run.wait(wait_for="running")

# Check status without blocking
if run.done():
print(f"Final phase: {run.phase}")

The wait method accepts a quiet parameter to suppress the visual progress bar and a wait_for parameter to specify the target state ("terminal" or "running").

Aborting a Run

If a run is no longer needed or is consuming excessive resources, you can terminate it using the abort method.

from flyte.remote import Run

run = Run.get(name="f7a2b3c4d5e6f7g8")
if not run.done():
run.abort()
print(f"Aborted run: {run.name}")

Inspecting Run Details and Data

For access to metadata, inputs, and outputs, use the RunDetails class. This provides a more comprehensive view of the execution than the base Run object.

from flyte.remote import RunDetails

details = RunDetails.get(name="f7a2b3c4d5e6f7g8")

# Access metadata
print(f"Task Name: {details.task_name}")
print(f"Is Interruptible: {details.pb2.run_spec.interruptible}")

# Retrieve inputs and outputs
inputs = details.inputs()
print(f"Input data: {inputs.data}")

if details.done():
outputs = details.outputs()
print(f"Output data: {outputs}")

Note that outputs() will raise a RuntimeError if called on a run that has not yet reached a terminal state.

Managing Individual Actions

A single Run consists of one or more Action attempts. You can inspect these for granular debugging, especially in cases of retries.

from flyte.remote import Action

# List all actions for a specific run
actions = Action.listall(for_run_name="f7a2b3c4d5e6f7g8")

for action in actions:
print(f"Action: {action.name} | Phase: {action.phase}")

# Show logs for the specific action attempt
action.show_logs(max_lines=50)

Accessing Logs

The Run class provides a shortcut to view logs for the underlying execution.

from flyte.remote import Run

run = Run.get(name="f7a2b3c4d5e6f7g8")

# Display the last 100 lines of logs
run.show_logs(max_lines=100)

# Show raw logs with timestamps
run.show_logs(raw=True, show_ts=True)

The show_logs method internally waits for logs to become available if the run is in a state where logs are still being processed.