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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With