Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommended Python publish/subscribe/dispatch module? [closed]

From PyPubSub:

Pypubsub provides a simple way for your Python application to decouple its components: parts of your application can publish messages (with or without data) and other parts can subscribe/receive them. This allows message "senders" and message "listeners" to be unaware of each other:

  • one doesn't need to import the other
  • a sender doesn't need to know
    • "who" gets the messages,
    • what the listeners will do with the data,
    • or even if any listener will get the message data.
  • similarly, listeners don't need to worry about where messages come from.

This is a great tool for implementing a Model-View-Controller architecture or any similar architecture that promotes decoupling of its components.

There seem to be quite a few Python modules for publishing/subscribing floating around the web, from PyPubSub, to PyDispatcher to simple "home-cooked" classes.

Are there specific advantages and disadvantages when comparing different different modules? Which sets of modules have been benchmarked and compared?

Thanks in advance

like image 756
Eli Bendersky Avatar asked Sep 22 '08 16:09

Eli Bendersky


3 Answers

PyDispatcher is used heavily in Django and it's working perfectly for me (and for whole Django community, I guess).

As I remember, there are some performance issues:

  • Arguments checking made by PyDispatcher is slow.
  • Unused connections have unnecessary overhead.

AFAIK it's very unlikely you will run into this issues in a small-to-medium sized application. So these issues may not concern you. If you think you need every pound of performance (premature optimization is the root of all evil!), you can look at modifications done to PyDispatcher in Django.

Hope this helps.

like image 58
zuber Avatar answered Sep 20 '22 08:09

zuber


The best dispatch package for python seems to be the dispatch module inside django (called signals in the documentation). It is independent of the rest of django, and is short, documented, tested and very well written.

Edit: I forked this project into an independent signal project for Python.

like image 4
Olivier Verdier Avatar answered Sep 21 '22 08:09

Olivier Verdier


Here is a newer one: https://github.com/shaunduncan/smokesignal. "smokesignal is a simple python library for sending and receiving signals. It draws some inspiration from the django signal framework but is meant as a general purpose variant." Example:

from time import sleep
import smokesignal

@smokesignal.on('debug')
def verbose(val):
    print "#", val


def main():
    for i in range(100):
        if i and i%10==0:
            smokesignal.emit('debug', i)
        sleep(.1)

main()
like image 3
Jabba Avatar answered Sep 23 '22 08:09

Jabba