Jackson Freitas
09/22/2025, 3:17 PMMarvin
09/22/2025, 3:17 PMMarvin
09/22/2025, 3:20 PM--detached
flag for prefect worker start
in Prefect 3.x.
Why it’s not there:
- Prefect intentionally doesn’t implement process supervision/daemonization in the CLI. Backgrounding a long‑running process is best handled by your OS or orchestrator (systemd, Docker, Kubernetes, etc.) to get proper restart policies, logging, and signal handling across platforms.
- I couldn’t find an official rationale or issue specifically discussing a --detached
flag.
Docs: Workers (Prefect 3.x)
Common ways to run a worker “detached”:
- Linux/macOS (quick and dirty):
nohup prefect worker start --pool test-work-pool > worker.out 2>&1 & disown
or run in `tmux`/`screen`.
- systemd (recommended on Linux):
[Unit]
Description=Prefect Worker
After=network.target
[Service]
Type=simple
User=prefect
WorkingDirectory=/opt/prefect
Environment="PREFECT_API_URL=..."
Environment="PREFECT_API_KEY=..."
ExecStart=/usr/bin/env bash -lc 'prefect worker start --pool test-work-pool'
Restart=always
RestartSec=5
StandardOutput=append:/var/log/prefect-worker.log
StandardError=append:/var/log/prefect-worker.err
[Install]
WantedBy=multi-user.target
Then:
sudo systemctl daemon-reload
sudo systemctl enable --now prefect-worker.service
- Docker (let Docker do the daemonization):
docker run -d --name prefect-worker \
-e PREFECT_API_URL=... \
-e PREFECT_API_KEY=... \
your-prefect-image \
prefect worker start --pool test-work-pool
- Kubernetes: run the worker as a Deployment so it’s always on and restarted by the scheduler.
If you’d like a native --detached
, feel free to open a feature request: Create a Prefect issue.
If you share your environment (OS, container/orchestrator, how you deploy), I can give you a tailored, copy‑paste setup.Nate
09/22/2025, 5:54 PMprefect server start
I could see why this might be useful, but can you explain your use case?Nate
09/22/2025, 5:55 PMJackson Freitas
09/22/2025, 6:33 PMNate
09/22/2025, 6:34 PMJackson Freitas
09/22/2025, 7:27 PMNate
09/22/2025, 7:27 PM