[Twisted-Python] How to get at applications in a reactor?

David E. Konerding dekonerding at lbl.gov
Wed Jun 21 12:57:10 EDT 2006

Jean-Paul Calderone wrote:
> On Wed, 21 Jun 2006 08:09:17 -0700, "David E. Konerding" 
> <dekonerding at lbl.gov> wrote:
>> Hi folks,.
>> I've set up a convenient telnet manhole into my application.  The 
>> application runs a web site serving up Static files
>> and some Resources.  What I want to do is telnet into the manhole and 
>> get access to the application object.
>> Unfortunately, the useful information is not bound to the local scope 
>> of the telnet manhole, so
>> I have to "stash" the application object when it is instantiated in 
>> some global place (such as sys._myapplication).
> You can populate the local namespace of the manhole.
> twisted.conch.manhole.Manhole takes a namespace argument to its __init__
> twisted.manhole.telnet.ShellFactory has a namespace instance attribute
> which you can populate after creating one.
Excellent, thanks!
> The reactor doesn't know anything about sites or applications, so it 
> can't
> give you a list of them.  It could give you a list of file 
> descriptors, but
> I don't think that would be very useful :)
Oh, yeah, I expected to get only file descriptors, and hoped that a bit 
of clever gc.get_referrers()
would help me walk back to the Site and Application objects.

Somebody must be keeping references to the Site and Application 
objects-- at least,
the twistd daemon that imported my .tac file, right?

> The gc module is also fairly handy with manhole.  For example,
> gc.get_referrers(SomeClass) will give you every instance of the
> given class which exists in the process at that time (it will
> give you some other stuff too, like a module dictionary, but you
> can use isinstance() to filter out just the instances).
Yep, when I played with this *all* I got back were module namespace 
dictionaries.  That's partly why I was so confused...


More information about the Twisted-Python mailing list