[Twisted-Python] cred realm with __init__ methods under twistd

Ross Vandegrift ross at kallisti.us
Mon Jul 7 19:08:16 EDT 2008

Hello everyone,

I'm working on a twisted application that uses cred and pb.  I'm
having a bit of trouble getting my realm working as I want.

In my .tac file, I have this:

p = portal.Portal(CNDRealm())
c = checkers.InMemoryUsernamePasswordDatabaseDontUse(user="passwd")
application = service.Application("receiver")
service = service.IServiceCollection(application)
factory = pb.PBServerFactory(p)
internet.TCPServer(8800, factory).setServiceParent(service)

My realm, CNDRealm, looks like this:

from globals import devs, queues, conditions, devices
class CNDRealm(object):
    def __init__(self):
        for i in devs:
            queues[i] = list()
            conditions[i] = threading.Condition()
            devices[i] = CNDDevice(i[0], socket.gethostbyname(i[0]), i[1], queues[i], conditions[i])
        log.msg("Initialized devices: " % devices)

    def requestAvatar(self, aid, min, *interfaces):
        log.msg("Avatar requested: %s" % aid)
        if pb.IPerspective not in interfaces:
            raise NotImplementedError
        return pb.IPerspective, CNDSubmitter(aid), lambda: None

However, I never get the log message from the __init__ method.  I know
that it's not being run because those dictionaries are never populated
with the data my app needs to be in there.

1) What's going on?  I'm pretty surprised to find that an object's
__init__ doesn't seem to be getting called!

2) Is there some better place in a twistd app to put general start-up
initialization kinds of things?

Ross Vandegrift
ross at kallisti.us

"The good Christian should beware of mathematicians, and all those who
make empty prophecies. The danger already exists that the mathematicians
have made a covenant with the devil to darken the spirit and to confine
man in the bonds of Hell."
	--St. Augustine, De Genesi ad Litteram, Book II, xviii, 37

More information about the Twisted-Python mailing list