[Twisted-Python] Service as a daemon

John Toohey jt at parspro.com
Thu Aug 12 22:03:41 EDT 2004

I do run it with twistd -f feedserver.tap. The factory starts up, but 
service.start is not called.

On Aug 12, 2004, at 7:49 PM, Jp Calderone wrote:

> John Toohey wrote:
>> Hi all,
>> I have a twisted server which can be started with the following code 
>> :-
>> if __name__=="__main__":
>>     application = service.Application('feedserver', uid=1, gid=1)
>>     f = FeedService('feedserver')
>>     reactor.connectTCP('localhost',8002,f.getFactory())
>>     f.setServiceParent(service.IServiceCollection(application))
>>     f.startService()
>>     reactor.run()
>   There's little point in using service.Application, if it is used as 
> above.  A better way to do this would be to put the above code into a 
> .tac file (adding the appropriate imports), remove the last two lines, 
> and run it with "twistd -y <filename.tac>".
>> The f.startService method makes a call to a database and using the PB 
>> layer, sends data to another twisted server every 5 minutes. However, 
>> when I try to create a .tap file and run it as a daemon with this 
>> code :-
>> def makeService(config):
>>     pbport = int(config["pbport"])
>>     application = service.Application('feedserver', uid=1, gid=1)
>>     f = FeedService('feedserver')
>>     serviceCollection = service.IServiceCollection(application)
>>     internet.TCPClient("localhost",pbport, 
>> f.getFactory()).setServiceParent(serviceCollection)
>>     f.startService()
>>     return serviceCollection
>> The f.startService method is not called, and the data is not sent to 
>> the other server. What am I missing here?
>   makeService is run when the .tap file is written.  That means 
> f.startService() is called when the .tap file is written.  Since the 
> reactor isn't running at this point, the connection will never happen. 
> When you later run this .tap file with "twistd -f <filename.tap>", I 
> would expect the connection to occur.  Are you running the resulting 
> tap file with "twistd -f"?
>   Jp
> _______________________________________________
> 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