[Twisted-Python] Application Start Up and Tear Down

glyph at divmod.com glyph at divmod.com
Mon Jul 9 07:31:57 MDT 2007


On 05:53 am, andrew-twisted at puzzling.org wrote:
>Pavel Bastov wrote:
>>Hi,
>>
>>so far I've been using only one Factory in my application. So, all the
>>intialization and deinitialization code was in startFactory() /
>>stopFactory().
>>
>>Now I have to add another protocol with another factory. Is there a
>>similar pair of methods for the application (server) where I can
>>initialize resources (db pool, for example) upon startup and free them
>>upon shutdown?
>
>Make your own Service subclass, and override startService/stopService.

I just want to reinforce that this is really the *correct* answer, and 
the other suggestions (custom code before/after run(), manually calling 
addSystemEventTrigger) both tightly bind your application logic to the 
particular way your entire process starts up and shuts down, rather than 
having a discrete unit for your application.  (Think global vs. instance 
variables.)

The service hierarchy has issues (privilegedStartService being the 
biggest one) but it is generally the most flexible, since you can start 
and stop services and groups of services without starting and stopping 
the entire process.




More information about the Twisted-Python mailing list