[Twisted-Python] untwisting twistd

Phil Christensen phil at bubblehouse.org
Wed Jun 24 11:18:29 EDT 2009

On Jun 23, 2009, at 11:27 AM, Jared Gisin wrote:
> In order to fire up the app with sane default, I should be able to  
> issue one command with no arguments as the defaults for all of those  
> should be baked into the system.
> I guess in the mean time, I'll just write my own custom  
> ServerOptions, which oddly, will mirror a bunch of code that already  
> exists.

Based on your use case, you really shouldn't need to duplicate much  
functionality at all.

Here's one way to make a custom runner that uses all the guts of the  
twistd stuff, but overrides various options. This example sets the  
pidfile to 'web.pid' and automatically runs the 'web' sub-command:

     from twisted.application import app
     from twisted.scripts.twistd import runApp

     from twisted.python.runtime import platformType
     if platformType == "win32":
         from twisted.scripts._twistw import ServerOptions
         from twisted.scripts._twistd_unix import ServerOptions

     class CustomServerOptions(ServerOptions):
         defaultSubCommand = 'web'
         optParameters = [
                           "Name of the pidfile"],

     if __name__ == '__main__':
         app.run(runApp, CustomServerOptions)

The biggest complication here is selecting the correct ServerOptions  
file to use as a base. As it is, this example will pick the correct  
ServerOptions base, but sets the pidfile default no matter what, which  
isn't applicable to the windows options, AFAIK.

I'm not suggesting it couldn't be better, but I don't know what  
specific changes would need to be made to satisfy everyone (or mostly  


More information about the Twisted-Python mailing list