Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6847387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:44:19+00:00 2026-05-27T00:44:19+00:00

I am using celery 2.4.1 with python 2.6, the rabbitmq backend, and django. I

  • 0

I am using celery 2.4.1 with python 2.6, the rabbitmq backend, and django. I would like my task to be able to clean up properly if the worker shuts down. As far as I am aware you cannot supply a task destructor so I tried hooking into the worker_shutdown signal.

Note: AbortableTask only works with the database backend so I cant use that.

from celery.signals import worker_shutdown

@task
def mytask(*args)

  obj = DoStuff()

  def shutdown_hook(*args):
     print "Worker shutting down"
     # cleanup nicely
     obj.stop()

  worker_shutdown.connect(shutdown_hook)

  # blocking call that monitors a network connection
  obj.stuff()

However, the shutdown hook never gets called. Ctrl-C’ing the worker doesnt kill the task and I have to manually kill it from the shell.

So if this is not the proper way to go about it, how do I allow tasks to shutdown gracefully?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:44:20+00:00Added an answer on May 27, 2026 at 12:44 am

    worker_shutdown is only sent by the MainProcess, not the child pool workers.
    All worker_* signals except for worker_process_init, refer to the MainProcess.

    However, the shutdown hook never gets called. Ctrl-C’ing the worker
    doesn’t kill the task and I have to manually kill it from the shell.

    The worker never terminates a task under normal (warm) shutdown.
    Even if a task takes days to complete, the worker won’t complete shutdown
    until it’s completed. You can set --soft-time-limit, or --time-limit to
    to tell the instance when it’s ok to terminate the task.

    So to add any kind of process cleanup process you first need to
    make sure that the tasks can actually complete. As the cleanup wouldn’t
    be called before that happens.

    To add a cleanup step to the pool worker processes you can use
    something like:

    from celery import platforms
    from celery.signals import worker_process_init
    
    def cleanup_after_tasks(signum, frame):
        # reentrant code here (see http://docs.python.org/library/signal.html)
    
    def install_pool_process_sighandlers(**kwargs):
        platforms.signals["TERM"] = cleanup_after_tasks
        platforms.signals["INT"] = cleanup_after_tasks
    
    worker_process_init.connect(install_pool_process_sighandlers)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using celery with django and am trying to get a Task, like the
I am running Celery 2.2.4/djCelery 2.2.4, using RabbitMQ 2.1.1 as a backend. I recently
I am using Django with Celery + RabbitMQ to create video conversion tasks of
I'm using Django, Celery, and Django-Celery. I'd like to monitor the state/results of my
I'm using the django celery task queue, and it works fine in development, but
I'm using Python with Celery and RabbitMQ to make a web spider to count
In a Django Python app, I launch jobs with Celery (a task manager). When
I would like to be able to abort a task that is running from
RabbitMQ now seems to be working correctly. However, when I try python -m celery.bin.celeryd
I'm using django-celery using the database as both broker and results store. The events

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.