| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 | .. _signals:=======Signals=======.. contents::    :local:Signals allows decoupled applications to receive notifications whencertain actions occur elsewhere in the application.Celery ships with many signals that you application can hook intoto augment behavior of certain actions... _signal-basics:Basics======Several kinds of events trigger signals, you can connect to these signalsto perform actions as they trigger.Example connecting to the :signal:`task_sent` signal:.. code-block:: python    from celery.signals import task_sent    def task_sent_handler(sender=None, task_id=None, task=None, args=None,                          kwargs=None, \*\*kwds):        print("Got signal task_sent for task id %s" % (task_id, ))    task_sent.connect(task_sent_handler)Some signals also have a sender which you can filter by. For example the:signal:`task_sent` signal uses the task name as a sender, so you canconnect your handler to be called only when tasks with name `"tasks.add"`has been sent by providing the `sender` argument to:class:`~celery.utils.dispatch.signal.Signal.connect`:.. code-block:: python    task_sent.connect(task_sent_handler, sender="tasks.add").. _signal-ref:Signals=======Task Signals------------.. signal:: task_senttask_sent~~~~~~~~~Dispatched when a task has been sent to the broker.Note that this is executed in the client process, the one sendingthe task, not in the worker.Sender is the name of the task being sent.Provides arguments:* task_id    Id of the task to be executed.* task    The task being executed.* args    the tasks positional arguments.* kwargs    The tasks keyword arguments.* eta    The time to execute the task.* taskset    Id of the taskset this task is part of (if any)... signal:: task_preruntask_prerun~~~~~~~~~~~Dispatched before a task is executed.Sender is the task class being executed.Provides arguments:* task_id    Id of the task to be executed.* task    The task being executed.* args    the tasks positional arguments.* kwargs    The tasks keyword arguments... signal:: task_postruntask_postrun~~~~~~~~~~~~Dispatched after a task has been executed.Sender is the task class executed.Provides arguments:* task_id    Id of the task to be executed.* task    The task being executed.* args    The tasks positional arguments.* kwargs    The tasks keyword arguments.* retval    The return value of the task... signal:: task_failuretask_failure~~~~~~~~~~~~Dispatched when a task fails.Sender is the task class executed.Provides arguments:* task_id    Id of the task.* exception    Exception instance raised.* args    Positional arguments the task was called with.* kwargs    Keyword arguments the task was called with.* traceback    Stack trace object.* einfo    The :class:`celery.datastructures.ExceptionInfo` instance.Worker Signals--------------.. signal:: worker_initworker_init~~~~~~~~~~~Dispatched before the worker is started... signal:: worker_readyworker_ready~~~~~~~~~~~~Dispatched when the worker is ready to accept work... signal:: worker_process_initworker_process_init~~~~~~~~~~~~~~~~~~~Dispatched by each new pool worker process when it starts... signal:: worker_shutdownworker_shutdown~~~~~~~~~~~~~~~Dispatched when the worker is about to shut down.Celerybeat Signals------------------.. signal:: beat_initbeat_init~~~~~~~~~Dispatched when celerybeat starts (either standalone or embedded).Sender is the :class:`celery.beat.Service` instance... signal:: beat_embedded_initbeat_embedded_init~~~~~~~~~~~~~~~~~~Dispatched in addition to the :signal:`beat_init` signal when celerybeat isstarted as an embedded process.  Sender is the:class:`celery.beat.Service` instance.Eventlet Signals----------------.. signal:: eventlet_pool_startedeventlet_pool_started~~~~~~~~~~~~~~~~~~~~~Sent when the eventlet pool has been started.Sender is the :class:`celery.concurrency.eventlet.TaskPool` instance... signal:: eventlet_pool_preshutdowneventlet_pool_preshutdown~~~~~~~~~~~~~~~~~~~~~~~~~Sent when the worker shutdown, just before the eventlet poolis requested to wait for remaining workers.Sender is the :class:`celery.concurrency.eventlet.TaskPool` instance... signal:: eventlet_pool_postshutdowneventlet_pool_postshutdown~~~~~~~~~~~~~~~~~~~~~~~~~~Sent when the pool has been joined and the worker is ready to shutdown.Sender is the :class:`celery.concurrency.eventlet.TaskPool` instance... signal:: eventlet_pool_applyeventlet_pool_apply~~~~~~~~~~~~~~~~~~~Sent whenever a task is applied to the pool.Sender is the :class:`celery.concurrency.eventlet.TaskPool` instance.Provides arguments:* target    The target function.* args    Positional arguments.* kwargs    Keyword arguments.Logging Signals---------------.. signal:: setup_loggingsetup_logging~~~~~~~~~~~~~Celery won't configure the loggers if this signal is connected,so you can use this to completely override the logging configurationwith your own.If you would like to augment the logging configuration setup byCelery then you can use the :signal:`after_setup_logger` and:signal:`after_setup_task_logger` signals.Provides arguments:* loglevel    The level of the logging object.* logfile    The name of the logfile.* format    The log format string.* colorize    Specify if log messages are colored or not... signal:: after_setup_loggerafter_setup_logger~~~~~~~~~~~~~~~~~~Sent after the setup of every global logger (not task loggers).Used to augment logging configuration.Provides arguments:* logger    The logger object.* loglevel    The level of the logging object.* logfile    The name of the logfile.* format    The log format string.* colorize    Specify if log messages are colored or not... signal:: after_setup_task_loggerafter_setup_task_logger~~~~~~~~~~~~~~~~~~~~~~~Sent after the setup of every single task logger.Used to augment logging configuration.Provides arguments:* logger    The logger object.* loglevel    The level of the logging object.* logfile    The name of the logfile.* format    The log format string.* colorize    Specify if log messages are colored or not.
 |