It can be useful, at least during application development, to have some code called when pubsub takes certain types of actions. Pubsub supports “notification handlers” and notification flags:
a notification handler is an instance of a class that defines several methods to handle one, more or all of the types of notifications supported by pubsub
a notification flag is a boolean used to toggle a particular type of notification on or off; there are several types of notifications:
subscribe
sendMessage
newTopic
delTopic
listenerDead
The notification flags are changed via pub.setNotifications():
A notification handler must adhere to the INotificationHandler protocol defined in pubsub.utils modules:
import pubsub.utils
class MyNotifHandler(INotificationHandler):
def onSendMessage(...):
pub.addNotificationHandler( MyNotifHandler() )
A notification handler is held by strong reference.