[Twisted-Python] Service.stopService
I have a very simple application--I'm testing service start and stop. Woops--stopService is never called. Why? Here's my simpleService.py: from twisted.application import service class SimpleService(service.Service): def startService(self): service.Service.startService(self) print '***start' def stopService(self): service.Service.stopService(self) print '***stop' And here's my twistd script: from twisted.application import service import simpleService application = service.Application('testService', uid=1, gid=1) serviceCollection=service.IServiceCollection(application) w = simpleService.SimpleService() s.setServiceParent(serviceCollection) It logs ***start, just fine. But never ***stop! Is something broken? Or should I be using addSystemEventTrigger??? Bill la Forge http://www.geocities.com/laforge49/ Yahoo! India Matrimony: Find your partner online.
Bill la Forge wrote:
I have a very simple application--I'm testing service start and stop. Woops--stopService is never called. Why?
Here's my simpleService.py:
from twisted.application import service class SimpleService(service.Service): def startService(self): service.Service.startService(self) print '***start' def stopService(self): service.Service.stopService(self) print '***stop' And here's my twistd script:
from twisted.application import service import simpleService application = service.Application('testService', uid=1, gid=1) serviceCollection=service.IServiceCollection(application) w = simpleService.SimpleService() s.setServiceParent(serviceCollection) It logs ***start, just fine. But never ***stop!
Is something broken? Or should I be using addSystemEventTrigger???
I see different behavior. After changing the last line to use "w" instead of "s": exarkun@boson:~$ twistd -noy simple.tac 2004/05/21 09:52 EDT [-] Log opened. 2004/05/21 09:52 EDT [-] twistd 1.3.0rc1 (/usr/bin/python 2.3.3) starting up 2004/05/21 09:52 EDT [-] reactor class: twisted.internet.default.SelectReactor 2004/05/21 09:52 EDT [-] Loading simple.tac... 2004/05/21 09:52 EDT [-] Loaded. 2004/05/21 09:52 EDT [-] set uid/gid 1000/1000 2004/05/21 09:52 EDT [-] ***start 2004/05/21 09:52 EDT [-] Received SIGINT, shutting down. 2004/05/21 09:52 EDT [-] ***stop 2004/05/21 09:52 EDT [-] Main loop terminated. 2004/05/21 09:52 EDT [-] Server Shut Down. exarkun@boson:~$ Jp
On Fri, May 21, 2004 at 02:34:41PM +0100, Bill la Forge wrote:
I have a very simple application--I'm testing service start and stop. Woops--stopService is never called. Why?
[...]
And here's my twistd script:
from twisted.application import service import simpleService application = service.Application('testService', uid=1, gid=1) serviceCollection=service.IServiceCollection(application) w = simpleService.SimpleService() s.setServiceParent(serviceCollection)
This doesn't look like your real twistd script -- 's' isn't defined. Did your copy-and-paste screw something up? -Andrew.
More like copy/paste/cleanup I've since updated things... I'm thinking that perhaps the log is shutdown. So I'm now writing files. I get the start file, but not the stop file: from twisted.application import service from twisted.internet import reactor class SimpleService(service.Service): def startService(self): service.Service.startService(self) reactor.addSystemEventTrigger('before','shutdown',self.stopService) f=open('start.txt','w') f.close() def stopService(self): f=open('stop.txt','w') f.write('KillJoy was here?') f.close() service.Service.stopService(self) from twisted.application import service from twisted.internet import reactor import simpleService application = service.Application('testServer') serviceCollection=service.IServiceCollection(application) ss=simpleService.SimpleService() ss.setServiceParent(serviceCollection) reactor.stop() C:\other\Bill\compstrm\compstrm\twbsd>twistd -noy testService.py 2004/05/21 19:29 India Standard Time [-] Log opened. 2004/05/21 19:29 India Standard Time [-] twistd 1.2.0 (C:\Python23\python.exe 2. 3.3) starting up 2004/05/21 19:29 India Standard Time [-] reactor class: twisted.internet.default .SelectReactor 2004/05/21 19:29 India Standard Time [-] Main loop terminated. 2004/05/21 19:29 India Standard Time [-] Server Shut Down. C:\other\Bill\compstrm\compstrm\twbsd> Now, since its working for others, let me further report that I'm running on nt2000 with twisted 1.2. Mmm. Perhaps I'd best reinstall. I may have messed up some twisted code while adding print statements. :-O Bill la Forge http://www.geocities.com/laforge49/ Yahoo! India Matrimony: Find your partner online.
participants (3)
-
Andrew Bennetts
-
Bill la Forge
-
Jp Calderone