Repository navigation
Description
Checklist, related issues and environment
Checklist
- I have verified that the issue exists against the
mainbranch of Celery. - This has already been asked to the discussions forum first.
- I have read the relevant section in the
contribution guide
on reporting bugs. - I have checked the issues list
for similar or identical bug reports. - I have checked the pull requests list
for existing proposed fixes. - I have checked the commit log
to find out if the bug was already fixed in the main branch. - I have included all related issues and possible duplicate issues
in this issue (If there are none, check this box anyway). - I have tried to reproduce the issue with pytest-celery and added the reproduction script below. -> Not with pytest-celery, this needs a real worker plus a signal. Manual steps and unit tests below instead.
Mandatory Debugging Information
- I have included the output of
celery -A proj reportin the issue. - I have verified that the issue exists against the
mainbranch of Celery. - I have included the contents of
pip freezein the issue. - I have included all the versions of all the external dependencies required
to reproduce this bug.
Optional Debugging Information
- I have tried reproducing the issue on more than one Python version
and/or implementation. - I have tried reproducing the issue on more than one message broker and/or
result backend. - I have tried reproducing the issue on more than one version of the message
broker and/or result backend. - I have tried reproducing the issue on more than one operating system.
- I have tried reproducing the issue on more than one workers pool.
- I have tried reproducing the issue with autoscaling, retries,
ETA/Countdown & rate limits disabled. - I have tried reproducing the issue after downgrading
and/or upgrading Celery and its dependencies.
Related Issues and Possible Duplicates
Related Issues
- Terminate job implementation for gevent concurrency backend #8687 (closed), the same feature request for gevent, implemented in Terminate job implementation for gevent concurrency backend #9083 (merged).
- I can‘t stop a task by its task_id #5209 (closed), the same
NotImplementedErrorfor eventlet back in 2018, since fixed. - Signal-driven exceptions are not generally safe #10271 (closed), the cold shutdown docs already warn that terminating at an arbitrary point is not atomic.
Possible Duplicates
- None
Environment & Settings
Celery version: reproduced on main at 5dc781f.
software -> celery:5.6.2 kombu:5.6.2 py:3.12.3
platform -> Ubuntu 24.04
loader -> celery.loaders.app.AppLoader
settings -> broker_url: redis://localhost:6379/0
result_backend: redis://localhost:6379/1
worker_soft_shutdown_timeout: 3
task_acks_late: True
deprecated_settings: None
pip freeze Output:
amqp==5.3.1
billiard==4.2.4
celery @ git+https://github.com/celery/celery@5dc781f0b
click==8.4.2
click-didyoumean==0.3.1
click-plugins==1.1.1.2
click-repl==0.3.0
kombu==5.6.2
packaging==26.2
prompt_toolkit==3.0.52
python-dateutil==2.9.0.post0
redis==6.4.0
six==1.17.0
tzdata==2026.3
vine==5.1.0
wcwidth==0.8.2
Steps to Reproduce
worker_soft_shutdown_timeout = 3,task_acks_late = True, redis brokercelery -A app worker --pool threads -c 4- queue a handful of
time.sleep(20)tasks, wait until 4 of them run kill -QUIT <pid>: traceback below at +3s, worker exits only at ~20skill -KILL <pid>at +10s, which is what a supervisor does: the unacked messages stay parked
Actual Behavior
TaskPool.terminate_jobisn't implemented, so anything that tries hits theNotImplementedErrorfrom the base class.on_stopwaits for the termination to finish, but never does. Together with point 1 this means non-revoked tasks on shutdown.--pool=threadscan't cancel a running task.
revoke(terminate=True) hits the same thing, which is what #5209 was about for eventlet, but I'm mostly interested in shutdowns.
This is kinda worse for redis transport, because there visibility_timeout needs to be quite large, so in combination with acks_late one gets more unacked messages being lost for a while.
Expected Behavior
Roughly what gevent got in #9083.
Threads can't be killed, but PyThreadState_SetAsyncExc would get you most of the way. Best-effort, but fine I would say and better than the pool raising. Also other libraries like dramatiq use this.
And with that in place the cold shutdown finishes within the soft timeout, so unacked messages go back to the broker before the supervisor kills the worker..
I have a branch, will open the PR right after this.
Activity
[-]Threads pool has no terminate_job, so revoke(terminate=True) and cold shutdown raise NotImplementedError[/-][+]Threads pool has no terminate_job, so revoke and cold shutdown don't have expected behavior[/+]