Eryk Sun <eryk...@gmail.com> added the comment:

Creating the py.exe process with creationflags=DETACHED_PROCESS sets a special 
ConsoleHandle value in its ProcessParameters that makes the base API skip 
allocating a console session at process startup. However, the launcher itself 
spawns python.exe normally, without the DETACHED_PROCESS flag. So the base API 
in the python.exe process allocates a new console session that creates a window.

Using creationflags=CREATE_NO_WINDOW resolves the problem. This flag makes the 
base API in the py.exe process allocate a new console session that doesn't 
create a window. The child python.exe process inherits this windowless console 
session. Note that CREATE_NO_WINDOW is ignored if combined with 
CREATE_NEW_CONSOLE or DETACHED_PROCESS, since the combination makes no sense.

You can also use creationflags=CREATE_NEW_CONSOLE with 
startupinfo=STARTUPINFO(dwFlags=STARTF_USESHOWWINDOW), in which case py.exe 
allocates a console session with a hidden window. This option is useful if a 
console application should be able to show the console window later on via 
ShowWindow(GetConsoleWindow(), SW_SHOW). With CREATE_NO_WINDOW, in contrast, 
there is no window to show.

It should work if creationflags=DETACHED_PROCESS is combined with 
startupinfo=STARTUPINFO(dwFlags=STARTF_USESHOWWINDOW) because the launcher is 
supposed to clone its startup information to the child python.exe process, 
including dwFlags. But there's a bug in run_child in PC/launcher.c. It sets 
si.dwFlags to STARTF_USESTDHANDLES instead of using a bitwise OR to set the 
flag value.

----------
nosy: +eryksun

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41619>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to