This document describes the current stable version of Celery (5.2). For development docs, go here.

celery.utils.dispatch

Observer pattern.

class celery.utils.dispatch.Signal(providing_args=None, use_caching=False, name=None)[source]

Create new signal.

Keyword Arguments:
  • providing_args (List) – A list of the arguments this signal can pass along in a send() call.

  • use_caching (bool) – Enable receiver cache.

  • name (str) – Name of signal, used for debugging purposes.

connect(*args, **kwargs)[source]

Connect receiver to sender for signal.

Parameters:
  • receiver (Callable) –

    A function or an instance method which is to receive signals. Receivers must be hashable objects.

    if weak is True, then receiver must be weak-referenceable.

    Receivers must be able to accept keyword arguments.

    If receivers have a dispatch_uid attribute, the receiver will not be added if another receiver already exists with that dispatch_uid.

  • sender (Any) – The sender to which the receiver should respond. Must either be a Python object, or None to receive events from any sender.

  • weak (bool) – Whether to use weak references to the receiver. By default, the module will attempt to use weak references to the receiver objects. If this parameter is false, then strong references will be used.

  • dispatch_uid (Hashable) – An identifier used to uniquely identify a particular instance of a receiver. This will usually be a string, though it may be anything hashable.

  • retry (bool) – If the signal receiver raises an exception (e.g. ConnectionError), the receiver will be retried until it runs successfully. A strong ref to the receiver will be stored and the weak option will be ignored.

disconnect(receiver=None, sender=None, weak=None, dispatch_uid=None)[source]

Disconnect receiver from sender for signal.

If weak references are used, disconnect needn’t be called. The receiver will be removed from dispatch automatically.

Parameters:
  • receiver (Callable) – The registered receiver to disconnect. May be none if dispatch_uid is specified.

  • sender (Any) – The registered sender to disconnect.

  • weak (bool) – The weakref state to disconnect.

  • dispatch_uid (Hashable) – The unique identifier of the receiver to disconnect.

has_listeners(sender=None)[source]
receivers = None

Holds a dictionary of {receiverkey (id): weakref(receiver)} mappings.

send(sender, **named)[source]

Send signal from sender to all connected receivers.

If any receiver raises an error, the exception is returned as the corresponding response. (This is different from the “send” in Django signals. In Celery “send” and “send_robust” do the same thing.)

Parameters:
  • sender (Any) – The sender of the signal. Either a specific object or None.

  • **named (Any) – Named arguments which will be passed to receivers.

Returns:

of tuple pairs: [(receiver, response), … ].

Return type:

List

send_robust(sender, **named)

Send signal from sender to all connected receivers.

If any receiver raises an error, the exception is returned as the corresponding response. (This is different from the “send” in Django signals. In Celery “send” and “send_robust” do the same thing.)

Parameters:
  • sender (Any) – The sender of the signal. Either a specific object or None.

  • **named (Any) – Named arguments which will be passed to receivers.

Returns:

of tuple pairs: [(receiver, response), … ].

Return type:

List