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

Eric Mangold teratorn at twistedmatrix.com
Fri Feb 2 20:07:44 EST 2007

On Fri, 02 Feb 2007 11:05:40 -0600, Steve Freitas <sflist at ihonk.com> wrote:

> Thanks for the very informative replies, Eric.
> On Fri, 2007-02-02 at 05:27 -0600, Eric Mangold wrote:
>> > Processes on Windows will inherit the parent's console by default. So
>>> when you run from the command-line it doesn't need to create a new
>>> one.
>> Actually CREATE_NO_WINDOW might be the flag you want. I'm not 100%
>> sure w/o running some tests.
> Okay... So I've got to somehow figure out how to launch the parent
> Twisted instance with CREATE_NO_WINDOW (or DETACHED_PROCESS, or
> whatever), then?

Well, no. Since you aren't seeing a console window I assume that  
pythonservice.exe is already doing that for you. Your challenge is to  
launch the child process in the same fashion.

> I'm using Hammond's pythonservice.exe, which was a side effect of using
> this approach to installing and running the Windows service:
> http://twistedmatrix.com/pipermail/twisted-python/2006-August/013790.html
> Also, I have access to the source code of the process I'm launching --
> if I can't figure out how to solve this from the Twisted side, might I
> be able to resolve it by modifying the process I'm launching?
> Steve

It's better to control the parent process. You can easily use  
CreateProcess yourself, and use OpenProcess followed by TerminateProcess  
to kill it. All these functions are in pywin32 which you already have if  
you're using spawnProcess.

You *can*, however, close the console after it's created. Just call  
FreeConsole(). This will have the effect of flashing a console window on  
the screen for a split second. Depending on how you run your service it  
may not have access to the desktop, and I'm not sure if this will cause  
problems with launching processes that try to create console windows.

Alternatively, since this is python, and you don't care about I/O, you can  
use pythonw.exe instead.

Hope that helps,
Eric Mangold
Twisted/Win32 Co-Maintainer

More information about the Twisted-Python mailing list