[Twisted-Python] Suppressing terminal window from reactor.spawnProcess?

Steve Freitas sflist at ihonk.com
Mon Feb 5 04:47:21 EST 2007

On Fri, 2007-02-02 at 05:27 -0600, Eric Mangold wrote:
> > But when run as a service I suspect that the parent process (Twisted) is  
> > created DETACHED, so it doesn't have a console. But when you spawn a new  
> > child it just uses the defaults which then gives you a console.
> >
> > For what it's worth the win32 API flag of interest is DETACHED_PROCESS  
> > documented here: http://msdn2.microsoft.com/en-us/library/ms684863.aspx
> >
> > spawnProcess is currently slated for a redesign as per  
> > http://twistedmatrix.com/trac/ticket/2415
> >
> > I will make sure this concern is address in some form or fashion, but in  
> > the mean time you will have to do some work yourself if you really need  
> > this feature. Let use know if you get stuck :)
> Actually CREATE_NO_WINDOW might be the flag you want. I'm not 100% sure  
> w/o running some tests.

Just to follow up for posterity, I ended up solving my problem.

First I overrode t.i.posixbase.PosixReactorBase.spawnProcess() with my
own function, the method for which now looks like:

def spawnProcess(self, processProtocol, executable, args=(),
	env={}, path=None, uid=None, gid=None, usePTY=0,
	childFDs=None, win32flags=0):

And inside spawnProcess(), when it goes to create a Process object, I
changed the line to read:

if win32process:
	return Process(self, processProtocol, executable, args,
		env, path, win32flags)

Then I overrode t.i._dumbwin32proc.Process' __init__ function, adding
win32flags to the end of the method's arguments as before, so it looks

def __init__(self, reactor, protocol, command, args, environment,
	path, win32flags=0):

Then, I modded its nested doCreate() function's call to be:

def doCreate():
	self.hProcess, self.hThread, dwPid, dwTid = \
	win32process.CreateProcess(command, cmdline, None, None,
		1, win32flags, env, path, StartupInfo)

And now that I'm passing win32con.DETACHED_PROCESS into my new
spawnProcess(), it works perfectly. I've got stdin/out/err, a proper way
to kill the process I spawned, and no annoying shell window opening.
Just what I wanted for Christmas.

One question: I noticed that the posix reactor is what's running on
Windows -- under what condition does win32eventreactor.Win32Reactor
actually get installed?

Thanks again for your help with this,


More information about the Twisted-Python mailing list