2

I need to allow other Python applications to register callback functions for events in my application. These need to have priorities associated with them (so a callback with a priority of 10 runs before a callback with a priority of 1) and callback functions need to be able to signal errors to the dispatcher.

These are all lightweight callbacks running in the same process, so I don't need to send signals across process boundaries.

Is there a good Python library to handle this, or do I need to write my own?

Chris B.
  • 85,731
  • 25
  • 98
  • 139

4 Answers4

1

Are these other applications running in another address space? If so, you'll need to use an interprocess communication library like D-BUS.

If you're just sending signals in the same process, try PyDispatcher

John Millikin
  • 197,344
  • 39
  • 212
  • 226
  • Does PyDispatcher allow callers to set the priority of their methods? Or return values? – Chris B. Sep 23 '08 at 00:14
  • No priority, but that's something you can write the signal registration function to perform. Not sure what you mean by return values -- I believe PyDispatcher returns the result of calling all the callbacks as a list. – John Millikin Sep 23 '08 at 03:39
0

Try Twisted for anything network-related. Its perspective broker is quite nice to use.

0

What platform are you running under? GObject is the basis of the GTK GUI that's widely-used under Linux, and it supports event loops with prioritizable events like this.

Dan Lenski
  • 76,929
  • 13
  • 76
  • 124
0

Try python-callbacks - http://code.google.com/p/python-callbacks/.

bhadra
  • 12,887
  • 10
  • 54
  • 47