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

Jean-Paul Calderone exarkun at divmod.com
Wed Jun 21 12:19:09 EDT 2006


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.

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 :)

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).

Jean-Paul




More information about the Twisted-Python mailing list