[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Events in Python

Simon Pickles

1/30/2008 8:16:00 PM

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://coun....



4 Answers

Ivan Illarionov

1/30/2008 10:04:00 PM

0

You may need Louie (http://louie....)
Django (http://djangop...) does the same in django.dispatch -
and Django version works about 33% faster.

Note that all those signals/events are very slow in Python.

--Ivan

Bjoern Schliessmann

1/30/2008 10:09:00 PM

0

Ivan Illarionov wrote:

> Note that all those signals/events are very slow in Python.

Compared to what, did you measure something?

Regards,


Björn

--
BOFH excuse #38:

secretary plugged hairdryer into UPS

Ivan Illarionov

1/30/2008 10:25:00 PM

0

> Compared to what, did you measure something?

As example, instantiation of Model classes in Django (Model.__init__)
sends two signals (pre_init and post_init) - they are rarely used in
practice - but they make instantiation about two times slower. Yes, I
measured that.

The creator of Louie (Patrick K. O'Brien) himself seems to use them
only as an option that can be enabled/disabled in his projects (e.g.
Schevo) - because they are slow.

alex23

1/31/2008 12:55:00 AM

0

Hey Si,

The PEAK lib Trellis (http://peak.telecommunity.com/DevCent...)
is worth checking out. I haven't had a chance to use it yet but am
keen to.

There are several other modules that may apply, I recommend searching
on the Python Package Index (http://pypi.pytho...), for
"observer" or "dispatcher".

Hope this helps.

-alex23