DEV Community

Cover image for I killed my Python worker with kill -9. The job still finished.
bzucker4
bzucker4

Posted on AI-assisted

I killed my Python worker with kill -9. The job still finished.

The job that quietly disappears

If you run background jobs in Python, you have probably lost one without knowing it. A deploy restarts your workers, the kernel kills a process that ran out of memory, or a host just goes away. The job that was running at that moment is gone. Nothing errors. Nothing retries. Someone notices a week later that a customer never got their receipt.

This is not exotic. By default, Celery acknowledges a task when a worker receives it, before the task runs. If the worker dies halfway through, that task is lost unless you turn on acks_late and tune the broker's visibility timeout. Most teams find that setting after the incident, not before.

I wanted a job library where surviving a crash is the default, not a setting you have to know about. So I built Steady.

How Steady keeps the job

When a Steady worker picks up a job, it does not just take it. It takes a lease: a deadline (60 seconds by default) and a random token, stored atomically in Redis or Postgres. While the job runs, the worker renews that lease every 20 seconds.

If the worker dies, the renewals stop. The lease runs out, and any other worker's housekeeping loop puts the job back at the front of its queue. The job can run far longer than 60 seconds; the lease only decides how quickly a dead worker's jobs come back.

Two details make this safe rather than just hopeful:

  • Stale workers cannot overwrite newer runs. Every outcome (success, retry, dead) is only accepted if the worker still holds the lease token. A worker that froze past its lease and then woke up gets its report rejected instead of clobbering the run that replaced it.
  • Poison jobs cannot take down the fleet. A job that keeps killing its worker (a memory blowup, a crash in a C extension) is counted. After three recoveries it goes to the dead set for a human to look at, instead of crashing your workers one at a time forever.

The demo

Here is the whole test. A task that sleeps for 4 seconds:

import time

from steady import Steady

app = Steady("redis://localhost:6379/0")

@app.task
def slow(seconds: float) -> str:
    time.sleep(seconds)
    return "finished"

slow.enqueue(4)
Enter fullscreen mode Exit fullscreen mode

Start a worker with a short lease, kill it mid-job, start another:

steady worker jobs:app --lease 3 &
sleep 1.5
kill -9 $!          # no cleanup, no goodbye
steady worker jobs:app --lease 3
Enter fullscreen mode Exit fullscreen mode

A few seconds later, the job's record says:

state succeeded | result finished | recoveries 1 | attempts 2
Enter fullscreen mode Exit fullscreen mode

The first worker died holding the job. The second worker noticed the lease had expired, put the job back, ran it, and recorded that it had been recovered once. The demo uses a three-second lease to make recovery easy to observe.

What else ships in 0.1.0

Surviving crashes is the headline, but the point of Steady is that the production behaviour is turned on by default:

  • Retries with exponential backoff and jitter: 20 retries over roughly two days, then a dead set you can inspect and retry from.
  • Unique jobs, rate limits and concurrency limits, including per-customer limits, across every worker.
  • Cron that fires each tick exactly once no matter how many workers you run.
  • Batches with completion callbacks, async tasks, and middleware.
  • Postgres transactional enqueue: pass your own connection and the job commits or rolls back with your data.
  • A dashboard for queues, latency, retries, dead jobs with tracebacks and per-task failure rates, which mounts in FastAPI or Django.

Every backend feature runs through one shared test suite against memory, Redis and Postgres.

The honest part

Steady is at-least-once. A job that was running when its worker died will run again, so tasks should be safe to run twice. Steady gives you current_job().id, which stays the same across retries, as an idempotency key for payment and email providers. Every crash-safe queue has this contract; the alternative is losing jobs.

It is also alpha. The API may change before 1.0. Known limits (timeouts only for async tasks, fixed-window rate limits, no Redis Cluster) are written down in the production guide rather than discovered in production.

Try it

pip install "steady-jobs[redis]"
Enter fullscreen mode Exit fullscreen mode

The code, docs and the crash test live at github.com/bzucker4/steady. If you try it, I would genuinely like to hear what broke, what was confusing, and what you wish it did. Open an issue or reply here.

Top comments (0)