[Twisted-Python] Re: twisted application server

Phil Mayers p.mayers at imperial.ac.uk
Fri Mar 7 13:35:06 EST 2008

Phil Mayers wrote:
> Mike Pelletier wrote:
>> On Fri, Mar 7, 2008 at 8:36 AM, Phil Mayers <p.mayers at imperial.ac.uk> 
>> wrote:
>>>  If you fork a python interpreter, you should very quickly replace the
>>>  process with exec.
>> Does fork+exec have any advantages over spawn?
> If you mean "os.spawnXX" I think that, under Unix, those *are* fork & 
> exec, so no - they're identical.

Sorry - to reply to myself and try to be more clear:

In almost all circumstances, regardless of whether you're using Twisted 
or not, fork'ing a python interpreter and leaving both parent and child 
running off the same memory image for any length of time is unwise.

In that respect, os.spawnXX == fork/exec and is thus fine. However...

> I don't think there's a native unix syscall "spawn".
> Seems I recall there is something in the MS VC runtime named similar.
> Anyway - if we're talking about Twisted, you want to use the Twisted 
> support - reactor.spawnProcess and a subclass of t.i.p.ProcessProtocol 
> to talk to the child worker.
> reactor.spawnProcess does the right thing(tm)

In almost all circumstances when using Twisted, you should use 
reactor.spawnProcess or one of the util functions t.i.utils.getProcess*

More information about the Twisted-Python mailing list