[Twisted-Python] How to hook onto or append functionality to a class (from another class)?

Einar S. Idsø einar.twisted at norsk-esport.no
Thu Sep 9 16:27:57 EDT 2010

Hi Glyph, and thank you for your thorough and very helpful response. :)

On Wed, Sep 8, 2010 at 9:47 PM, Glyph Lefkowitz <glyph at twistedmatrix.com> wrote:
> It sounds like this is a pretty trivial application of the Publish/Subscribe
> pattern (or perhaps the Observer) pattern.
>  Add one general-purpose
> "list of observers that want to be notified (when X happens)" argument.
>  Then when your getProcessOutput() finishes, just do 'for something in
> self.observers: something.youJustGotServerStatus(newServerStatus)'.
Yes! Perfect! That sounds like it's exactly what I need, thank you :)

> usually makes sense to define an interface with a couple of interesting
> methods when you do this, so that you can have more methods.
Interfaces scare me, and I've been doing my best to avoid them in my
application. The primary reason being that I am the only developer, so
as long as I know what I'm doing I'll be alright. Although I'm not so
sure that I actually do...

> Please, please do not use t.p.hook.  I hope that we delete it one day.
Thanks for the advice. I'll stay away.

>> I hope this was somewhat comprehensible, and that there is an elegant
>> solution out there. :)
> Well, if my answer answers your question, then yes :).
It certainly does, and it is much appreciated. I'll just pop out on
Google for a few minutes to find some examples, and will get right
back to coding my app. Thanks again for taking the time to help a
novice out :)


More information about the Twisted-Python mailing list