Skip to content

Threads pool has no terminate_job, so revoke and cold shutdown don't have expected behavior #10490

Open

Description

@oliverhaas
Checklist, related issues and environment

Checklist

  • I have verified that the issue exists against the main branch 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 report in the issue.
  • I have verified that the issue exists against the main branch of Celery.
  • I have included the contents of pip freeze in 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

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

  1. worker_soft_shutdown_timeout = 3, task_acks_late = True, redis broker
  2. celery -A app worker --pool threads -c 4
  3. queue a handful of time.sleep(20) tasks, wait until 4 of them run
  4. kill -QUIT <pid>: traceback below at +3s, worker exits only at ~20s
  5. kill -KILL <pid> at +10s, which is what a supervisor does: the unacked messages stay parked

Actual Behavior

  1. TaskPool.terminate_job isn't implemented, so anything that tries hits the NotImplementedError from the base class.
  2. on_stop waits for the termination to finish, but never does. Together with point 1 this means non-revoked tasks on shutdown.
  3. --pool=threads can'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

  1. changed the title [-]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[/+] on Aug 16, 2026
  2. added this to the 5.8.0 milestone on Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions