[Twisted-Python] Service as a daemon
John Toohey
jt at parspro.com
Fri Aug 13 11:03:58 MDT 2004
Here it is. Thanks for take the time to look at it.
class FeedService(service.Service):
def __init__(self, *args):
self.parent.__init__(self, *args)
self.s = startup()
self.s.start()
def go(self):
d = self.getData()
d.addCallback(self.sendData)
d.addErrback(self.getDataError)
d.addCallback(self.dataSentOK)
def dataSentOK(self, data):
log.msg("dataSentOK", data)
self.call = reactor.callLater(10, self.go)
def getData(self):
log.msg("getData")
d = defer.Deferred()
self.call = reactor.callLater(2, d.callback,
self.s.data.getDataAsString())
return d
def sendData(self, data):
log.msg("sendData", data)
# Strip all whitespace
xml = ""
xml = xml.join(data.split())
oddsObj = SenderOdds("admiral","full", xml)
self.sender = Sender(oddsObj)
deferred = self.factory.getRootObject()
deferred.addCallback(self.sender.got_obj)
deferred.addErrback(self.getConnectionError)
return xml
def startService(self):
log.msg("start Service")
self.go()
service.Service.startService(self)
def stopService(self):
log.msg("stop Service")
service.Service.stopService(self)
self.call.cancel()
def getConnectionError(self,failure):
log.msg("Error in getConnection", failure)
def getDataError(self,failure):
log.msg("Error in getData", failure)
def getFactory(self):
log.msg("getFactory")
self.factory = ReconnectingPBClientFactory()
return self.factory
JT
On Aug 13, 2004, at 12:52 PM, Eugene Coetzee wrote:
> Prehaps you are overriding startService() somewhere along.
>
> Can you post the code for FeedService.
>
>
> John Toohey wrote:
>
>> Thanks for your help. I just tried this, but the startService method
>> is still not called. Is there something else I need to do?
>>
>> John
>>
>> On Aug 13, 2004, at 10:35 AM, Itamar Shtull-Trauring wrote:
>>
>>> On Fri, 2004-08-13 at 10:05, John Toohey wrote:
>>>
>>>> The .tap file is now as follows :-
>>>> def makeService(config):
>>>> pbport = int(config["pbport"])
>>>>
>>>> application = service.Application('feedserver', uid=1, gid=1)
>>>> f = FeedService('feedserver')
>>>> reactor.connectTCP('localhost',8002,f.getFactory())
>>>>
>>>> f.setServiceParent(service.IServiceCollection(application))
>>>
>>>
>
> --
> --
> ===============================================
> Reedflute Software Solutions
>
> Telephone -> 018 293 3236
> General information -> info at reedflute.com
> Project information -> projects at reedflute.com
> Web -> www.reedflute.com
> ===============================================
>
>
> _______________________________________________
> 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