Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - How are signals different from pubsub?

Django and Flask make use of signals — the latter uses the Blinker library. In the context of Python, Blinker and the Python pubsub library, how do signals and pubsub compare? When would I use one or the other?

like image 532
a paid nerd Avatar asked Mar 04 '11 20:03

a paid nerd


Video Answer


1 Answers

Blinker docs and PubSub docs.

As far as Blinker and PubSub go, they are the same thing. The difference is in how they go about it:

With Blinker when you subscribe to a signal you give the name of the signal, and when you activate the signal you pass the activating object.

With PubSub when you subscribe to a listener you give the name (same as Blinker), but when you notify the listener you pass the data directly as keyword arguments. Because of the keyword argument method of passing data, it is possible to have many more safety checks using PubSub.

Personally, I would go with Blinker as it matches my way of thinking better, but PubSub certainly has a place also.

like image 175
Ethan Furman Avatar answered Sep 22 '22 16:09

Ethan Furman