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

Chaz. eprparadocs at gmail.com
Wed Jun 21 12:41:20 EDT 2006

Here is some code I use that uses the global() parm in manhole.

from twisted.cred import portal,checkers
from twisted.conch import manhole, manhole_ssh
from twisted.application import internet

def ManholeFactory(namespace,**passwords) :
    realm = manhole_ssh.TerminalRealm()
    def getManhole(_): return manhole.Manhole(namespace)
    realm.chainedProtocolFactory.protocolFactory = getManhole
    p = portal.Portal(realm)

    f = manhole_ssh.ConchFactory(p)
    return f

class ManholeService(internet.TCPServer):
    def __init__(self,port,namespace,**passwords):

You invoke it like:

    # Maybe start the manhole debugging service
    ManholeSrv = ManholeService(manholePort,

This will allow me access to everything in my application.


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.
> 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
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

More information about the Twisted-Python mailing list