Yu(Irene) Chen
04/09/2026, 7:52 AMMarvin
04/09/2026, 7:52 AMMarvin
04/09/2026, 7:54 AMfrom prefect import flow
@flow(timeout_seconds=3600) # 1 hour
def my_flow():
...
Any deployment of this flow will respect the timeout.
- If you’re using Kubernetes, enforce a pool‑wide hard cap via the work pool’s base job template
- Edit the work pool → Advanced → Base job template JSON and add a variable plus activeDeadlineSeconds in the job spec. For example:
{
"variables": {
"active_deadline_seconds": {
"title": "Active Deadline Seconds",
"description": "Max time the K8s job can run",
"default": 3600,
"type": "integer"
}
},
"job_configuration": {
"job_manifest": {
"spec": {
"activeDeadlineSeconds": "{{ active_deadline_seconds }}"
}
}
}
}
This applies to all jobs launched by that work pool and will hard‑terminate pods that exceed the deadline.
Recommended pattern:
- Use both: a flow‑level timeout_seconds for graceful cancellation, plus a Kubernetes activeDeadlineSeconds in the pool’s base job template as a safety net.
Would you like a step‑by‑step for your specific worker type (Kubernetes, Docker, Process, etc.)?
References:
- Flows and timeouts: Prefect docs – Flows
- Work pools and base job templates: Prefect docs – Work Pools
- Kubernetes integration: prefect-kubernetes collection