callback

Note

The following class is not intended for use by those using Pika in their applications. This documentation is for those who are extending Pika or otherwise working on the driver itself.

Callback management class, common area for keeping track of all callbacks in the Pika stack.

CallbackManager

class pika.callback.CallbackManager[source]

CallbackManager is a global callback system designed to be a single place where Pika can manage callbacks and process them. It should be referenced by the CallbackManager.instance() method instead of constructing new instances of it.

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

Add a callback to the stack for the specified key. If the call is specified as one_shot, it will be removed after being fired

The prefix is usually the channel number but the class is generic and prefix and key may be any value. If you pass in only_caller CallbackManager will restrict processing of the callback to only the calling function/object that you specify.

Parameters:
  • prefix (str or int) – Categorize the callback
  • key (object or str or dict) – The key for the callback
  • callback (method) – The callback to call
  • one_shot (bool) – Remove this callback after it is called
  • only_caller (object) – Only allow one_caller value to call the event that fires the callback.
  • arguments (dict) – Arguments to validate when processing
Return type:

tuple(prefix, key)

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

Remove all callbacks from the stack by a prefix. Returns True if keys were there to be removed

Parameters:prefix (str) – The prefix for keeping track of callbacks with
Return type:bool
clear()[source]

Clear all the callbacks if there are any defined.

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

Return count of callbacks for a given prefix or key or None

Parameters:
  • prefix (str or int) – Categorize the callback
  • key (object or str or dict) – The key for the callback
Return type:

None or int

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

Run through and process all the callbacks for the specified keys. Caller should be specified at all times so that callbacks which require a specific function to call CallbackManager.process will not be processed.

Parameters:
  • prefix (str or int) – Categorize the callback
  • key (object or str or dict) – The key for the callback
  • caller (Object) – Who is firing the event
  • args (list) – Any optional arguments
  • keywords (dict) – Optional keyword arguments
Return type:

bool

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

Remove a callback from the stack by prefix, key and optionally the callback itself. If you only pass in prefix and key, all callbacks for that prefix and key will be removed.

Parameters:
  • prefix (str) – The prefix for keeping track of callbacks with
  • key (str) – The callback key
  • callback_value (method) – The method defined to call on callback
  • arguments (dict) – Optional arguments to check
Return type:

bool

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

Remove all callbacks for the specified prefix and key.

Parameters:
  • prefix (str) – The prefix for keeping track of callbacks with
  • key (str) – The callback key

Project Versions

Table Of Contents

Previous topic

amqp_object

Next topic

channel

This Page