Wednesday, December 10, 2008

New boduch Python library.

I've made a new Python library called boduch available on pypi. Why did I call it boduch? Because it is simply a Python package where I can publish any cool Python tools and I couldn't think of a better name.

The current version has my first attempt at an event publishing system. Here is an example usage scenario.

#Event example using boduch.event

from boduch.event import Event, publish, subscribe, lock, unlock
from boduch.handle import Handle

class MyHandler(Handle):
def __init__(self, *args, **kw):
Handle.__init__(self, *args, **kw)

def run(self):
print "Got event",self.data["event"]

if __name__=="__main__":
subscribe(Event, MyHandler)
publish(Event)

Here, we have defined a simple handler that prints out the event it received. In the main program, we subscribe our handler to the base Event. We then publish our event.

No comments :

Post a Comment