Recommended Python publish/subscribe/dispatch module?

3,356

Solution 1

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.

Solution 2

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.

Solution 3

I recently looked carefully at py-amqplib to act as an AMQP client to a RabbitMQ broker. The latter tool is written in Erlang.

If you're looking to decouple your app. then why couple it to the language itself? Consider using message queues which are language neutral and then you've really got room to grow!

That being said, AMQP takes effort to understand and may be more than you are willing to take on if your app. is working just fine as is. YMMV.

Solution 4

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()

Solution 5

Some libraries I have found that haven't yet been mentioned:

Share:
3,356
checkmate711
Author by

checkmate711

Updated on March 25, 2020

Comments

  • checkmate711
    checkmate711 about 4 years

    for some reason PHP's imagettftext creates a funny looking text when I create the text at an angle.

    Below the source code. I can't post the image 'cause I don't have enough reputation points but the text looks like parts of the letters are cut off.

    Help!!!


    $text = 'My Text Is Messed Up!!!';
    $font = './fonts/arial.ttf';
    $font_size = 20;
    $font_multiplier = 0.5;
    
    $x=10; 
    $y=190; 
    $angle=45; 
    $width= ($font_size * $font_multiplier) * strlen($text); 
    echo $width;
    $height=200; 
    
    $size = imageTTFBBox($font_size, $angle, $font, $text);
    $img = imageCreateTrueColor($width, $height);
    imageSaveAlpha($img, true);
    ImageAlphaBlending($img, false);
    
    $transparentColor = imagecolorallocatealpha($img, 200, 200, 200, 127);
    imagefill($img, 0, 0, $transparentColor);
    $white = imagecolorallocate($img, 255, 255, 255);
    
    // Add the text
    imagettftext($img, $font_size, $angle, $x, $y, $white, $font, $text);
    
    // Using imagepng() results in clearer text compared with imagejpeg()
    imagepng($img, 'welcome-phrase.png');
    imagedestroy($img);
    

    EDIT: here's an example of the output (I changed text colour from white to black to make it visible on the white background - AG):

    enter image description here

    • Aleks G
      Aleks G almost 12 years
      I attached a sample output for you. Have to agree with you: it's really strange.
    • Pekka
      Pekka almost 12 years
      Ugh. Any chance you can use ImageMagick?
    • Admin
      Admin almost 12 years
      Weired indeed. Have you tried other fonts?