[Twisted-Python] Events in Python

Andy Fundinger Andy at NewWorldElectric.com
Wed Jan 30 15:50:43 EST 2008

Yeah, just keep a list of functions in your own code, no need to use twisted
for it and I've not seen twisted functions that really help.  something

class event(object):
  def __init__(self):
  def subscribe(self.f):
  def invoke(self,*args,*kwargs):
    for function in subscribers:

you can tweak that or whatever, but that's the basic pythonic way to do it
in my book(and in my code) a couple options to consider:
* in invoke, pass self to the function, I usually do that so I can have
functions that do whatever they do to the "event" subclass itself, as in a
clearOnFocus function attached to a text control which subclasses event,
whenever certain data is seen (type=focusEvent) clear the control.
* instead of storing functions store and .callback deffereds, of course
those can only be used once so change event.subscribe to event.wait for
clarity and reinitialize the list after invoke.

-Andy Fundinger

On Jan 30, 2008 3:15 PM, Simon Pickles <sipickles at hotmail.com> wrote:

> Hi,
> I have a stackless python app, using twisted in parts (.internet and
> .adbapi).
> I need a little help getting pythonic after years of c++ hell.
> I'd like to use a system of events and observers, like c++ boost.signal.
> I'd like to be able to subscribe multiple callbacks to a single function
> and cal them all using something like:
> event.invoke("some data to send with invocation")
> I'm thinking twisted callbacks do this:
>  def observe(self, f);
>      self.event.addcallback(f)
> Are there other ways?
> Thanks
> Si
> --
> Linux user #458601 - http://counter.li.org.
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Blog:  http://channel3b.wordpress.com
Second Life Name:  Ciemaar Flintoff

I am a sig Virus. Please put me in your sig so that I can continue to
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20080130/8000b961/attachment.htm 

More information about the Twisted-Python mailing list