[Twisted-Python] alternative to tac

Phil Christensen phil at bubblehouse.org
Tue Oct 7 09:16:13 MDT 2008


On Oct 7, 2008, at 5:18 AM, Werner Thie wrote:
> Vasil Vangelovski wrote:
>> Which is the simplest way to put a service under and application to
>> listen on a port and behave similarly to the way it behaves when run
>> with twistd -noy script.tac but directly from a standard python
>> module? Lets assume I don't have access to the tac command and want  
>> to
>> emulate the behaveour.
>
> Hi Vasil
>
> I use something along the code below whoch serves dual purpose, use  
> it with twistd -noy xxx.tac and also python xxx.tac.

[snip]

> def main():
>  log.startLogging(sys.stdout)
>  reactor.listenTCP(7999, site) #start only the web svc when debugging
>  reactor.run()
> ##  print gc.get_objects()
>
> if __name__ == '__main__':
>  main()

[snip]

I don't think this really emulates twistd's behavior very well. twistd  
does roughly one trillion other things during startup that won't  
happen here.

Maybe you don't need any of this stuff, but I'll add my two cents  
about how I've dealt with this, which is to use twistd plugins, and  
call twistd's script functions directly:

from twisted.scripts import twistd

config = twistd.ServerOptions()
args = ['--pidfile', 'mytwistd.pid', '-l', 'mytwistd.log', 'myplugin']
config.parseOptions(args)
twistd.runApp(config)

This lets me easily specify configuration details, but should be  
reasonably forward-compatible. Also, I can keep all my code inside a  
package, and as long as it's in the system path, my plugin will be  
available to twistd.

There was some talk ages ago about making twistd a little more  
developer-friendly (so that you could more easily pick and choose the  
parts of it you wanted to use) but I don't remember the details, or if  
any progress was made.

-phil




More information about the Twisted-Python mailing list