<DIV>If a service starts successfully, once initialization completes </DIV>
<DIV>successfully, it's stopService will be called for proper cleanup.</DIV>
<DIV>&nbsp;</DIV>
<DIV>However, if another service fails to successfully initialize, and it</DIV>
<DIV>is kind enough to call reactor.stop() rather than throw an exception,</DIV>
<DIV>then the first service can, at the end of its initialization, call</DIV>
<DIV>reactor.addSystemEventTrigger('before','shutdown',self.failedStartup),</DIV>
<DIV>then failedStartup() will be called and there is STILL a chance to</DIV>
<DIV>cleanup.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Here's the code, the script, and the twistd output:</DIV>
<DIV>&nbsp;</DIV>
<DIV>from twisted.application import service<BR>from twisted.internet import reactor</DIV>
<DIV>class SimpleService(service.Service):<BR>&nbsp;&nbsp;&nbsp; def startService(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; service.Service.startService(self)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reactor.addSystemEventTrigger('before','shutdown',self.failedStartup)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print '&gt;&gt;&gt;start'<BR>&nbsp;&nbsp;&nbsp; def stopService(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print '&gt;&gt;&gt;stop'<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; service.Service.stopService(self)<BR>&nbsp;&nbsp;&nbsp; def failedStartup(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print 'Oh!!!!!!!!!!!!!!!!!!!!!'<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>class FailService(service.Service):<BR>&nbsp;&nbsp;&nbsp; def startService(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reactor.stop()<BR></DIV>
<DIV>from twisted.application import service<BR>from twisted.internet import reactor</DIV>
<DIV>import simpleService</DIV>
<DIV>application = service.Application('testServer')<BR>serviceCollection=service.IServiceCollection(application)<BR>ss=simpleService.SimpleService()<BR>ss.setServiceParent(serviceCollection)<BR>fs=simpleService.FailService()<BR>fs.setServiceParent(serviceCollection)<BR></DIV>
<DIV>C:\other\Bill\compstrm\compstrm\twbsd&gt;twistd -noy testService.py<BR>2004/05/21 21:39 India Standard Time [-] Log opened.<BR>2004/05/21 21:39 India Standard Time [-] twistd 1.2.0 (C:\Python23\python.exe 2.<BR>3.3) starting up<BR>2004/05/21 21:39 India Standard Time [-] reactor class: twisted.internet.default<BR>.SelectReactor<BR>2004/05/21 21:39 India Standard Time [-] &gt;&gt;&gt;start<BR>2004/05/21 21:39 India Standard Time [-] Oh!!!!!!!!!!!!!!!!!!!!!<BR>2004/05/21 21:39 India Standard Time [-] Main loop terminated.<BR>2004/05/21 21:39 India Standard Time [-] Server Shut Down.</DIV>
<DIV>C:\other\Bill\compstrm\compstrm\twbsd&gt;</DIV><BR><BR>Bill la Forge<br>http://www.geocities.com/laforge49/<p><font face=arial size=-1>
<a href="http://in.rd.yahoo.com/specials/mailtg/*http://yahoo.shaadi.com/india-matrimony/" target="_blank">
<b>Yahoo! India Matrimony</a>:</b> Find your partner 
<a href="http://in.rd.yahoo.com/specials/mailtg2/*http://yahoo.shaadi.com/india-matrimony/community.php" target="_blank">online</a>.</font>