Skip to content

Worker Shutdown Signal Never Sent #1339

Closed

Description

@chrisw1229

The worker_init signal works fine for me, but the worker_shutdown signal never seems to fire. I did a search on the code base and found the worker_init signal is sent in celery/apps/worker.py, but when I searched for worker_shutdown I can't find anywhere that it is actually sent.

It could maybe added in the _shutdown_handler function, but due to the asynchronous aspect of terminating workers I'm not sure if that is entirely correct. Perhaps an atexit handler needs to be registered somewhere to actually send the signal?

Activity

  1. chrisw1229 commented on May 8, 2013

    @chrisw1229
    Author

    So I played around with this a bit more and I can see that sending the signal in _shutdown_handler means it can occur before all the worker processes are shutdown. An exception can be raised from _shutdown_handler or in the functions maybe_shutdown and consume_messages in consumer.py to actually shutdown the worker. Since it seems like there are multiple code paths for shutting down, I added an atexit handler to cover all cases that seems to work for me so far.

    I registered the handler as part of install_platform_tweaks:

    def install_platform_tweaks(self, worker):
        """Install platform specific tweaks and workarounds."""
    
        # Register a handler to send a shutdown signal when the worker exits
        import atexit
        atexit.register(lambda *a, **kw: _on_worker_shutdown(worker))

    And then added a new shutdown function:

    def _on_worker_shutdown(worker):
        signals.worker_shutdown.send(sender=worker)
  2. added a commit that references this issue on May 14, 2013
    ce6c932
  3. ask commented on May 14, 2013

    @ask
    Contributor

    Try this patch plase!

  4. chrisw1229 commented on May 15, 2013

    @chrisw1229
    Author

    @ask This new patch is working fine for me so far, tested under Windows and Linux. Thanks!

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

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions