<@ULVA73B9P> Prefect v2.20. I can start a backgro...
# marvin-ai
c
@Marvin Prefect v2.20. I can start a background process of the Prefect server with
prefect server start --background
. Can I create a background process for a Prefect worker too?
m
thought for 169.7 seconds
No—Prefect 2.20’s
prefect worker start
does not have a built-in
--background
option. For a quick background process on Linux/macOS:
Copy code
nohup prefect worker start --pool my-pool \
  > prefect-worker.log 2>&1 &

echo $! > prefect-worker.pid
Stop it gracefully with:
Copy code
kill "$(cat prefect-worker.pid)"
For a persistent worker, prefer a process manager such as
systemd
, Supervisor, Docker, or Kubernetes so it restarts after crashes or reboots. Also, Prefect 2.x is no longer under active development; current development is on Prefect 3.x.
c
@Marvin: What about Windows?
m
thought for 7.7 seconds
On Windows there’s still no Prefect-native
--background
option. From PowerShell, you can detach the worker with:
Copy code
$worker = Start-Process prefect `
  -ArgumentList "worker start --pool my-pool" `
  -WindowStyle Hidden `
  -RedirectStandardOutput "prefect-worker.log" `
  -RedirectStandardError "prefect-worker-error.log" `
  -PassThru

$worker.Id | Set-Content "prefect-worker.pid"
Stop it later with:
Copy code
Stop-Process -Id (Get-Content "prefect-worker.pid")
For a worker that should survive reboots and restart on failure, run it as a Windows service using a service manager such as NSSM, or use Windows Task Scheduler. That’s preferable to
Start-Process
for production.