This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients Bernat Gabor, eryksun, paul.moore, steve.dower, tim.golden, zach.ware
Date 2020-08-23.14:14:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1598192072.95.0.693372755708.issue41619@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2020-08-23 14:14:32eryksunsetrecipients: + eryksun, paul.moore, tim.golden, zach.ware, steve.dower, Bernat Gabor
2020-08-23 14:14:32eryksunsetmessageid: <1598192072.95.0.693372755708.issue41619@roundup.psfhosted.org>
2020-08-23 14:14:32eryksunlinkissue41619 messages
2020-08-23 14:14:32eryksuncreate