[Twisted-Python] an easy twisted application question
Phil Christensen
phil at bubblehouse.org
Wed Nov 12 11:25:06 MST 2003
so i followed jp's advice, and my makeService method now looks like this:
###############code#################
def makeService(config):
registry = Registry()
reg_service = RegistryService(registry)
portal = Portal(auth.InnerSpaceRealm(reg_service))
checker = auth.RegistryChecker(registry)
portal.registerChecker(checker)
pb_service = internet.TCPServer(int(config['port']),
pb.PBServerFactory(portal))
reg_service.setServiceParent(pb_service)
return pb_service
###############code#################
when i try to build my tap file now, i get
###############traceback#################
Traceback (most recent call last):
File "/Users/phil/Python/Twisted/bin/mktap", line 30, in ?
run()
File "/Users/phil/Python/Twisted/twisted/scripts/mktap.py", line 160, in
run
options.subOptions)
File "/Users/phil/Python/Twisted/twisted/scripts/mktap.py", line 58, in
makeService
ser = mod.makeService(options)
File "./inner/space/bigbang.py", line 24, in makeService
reg_service.setServiceParent(pb_service)
File "/Users/phil/Python/Twisted/twisted/application/service.py", line
116, in setServiceParent
self.parent.addService(self)
AttributeError: TCPServer instance has no attribute 'addService'
###############traceback#################
i've tried this both ways, with pb_service as the parent, and with
reg_service as the parent, with the same result.
btw, i am working out of a freshly checked-out cvs directory, but i doubt
that matters.
thanks again for any help,
-phil
> Newly written programs should implement makeService() instead of
> updateApplication(). As a bonus, purely service-based programs can easily
> and cleanly do things like the above:
>
> from twisted.application import service
>
> class RegistryService(service.Service):
> def __init__(self):
> self.registry = registry.Registry()
>
> def makeService(config):
> s = RegistryService()
> ...
> anotherS = SomeotherService()
> anotherS.setServiceParent(s) # Or s.setServiceParent(anotherS)
> ...
> return s # or return anotherS
>
> `s' can be the parent service of other services, in which case it can be
> accessed simply by looking up the parent service, or it could be a child
> service of something else, in which case it would be accessed via a call
> to getServiceNamed() on the appropriate parent.
More information about the Twisted-Python
mailing list