Skip to content

Commit 4527a37

Browse files
emmatypingJukkaL
authored andcommitted
Create new, hidden window when starting daemon on Windows (#5994)
1 parent c654871 commit 4527a37

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

mypy/dmypy_server.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,31 @@
4242
MEM_PROFILE = False # type: Final # If True, dump memory profile after initialization
4343

4444
if sys.platform == 'win32':
45+
from subprocess import STARTUPINFO
46+
4547
def daemonize(options: Options,
4648
timeout: Optional[int] = None,
4749
log_file: Optional[str] = None) -> int:
4850
"""Create the daemon process via "dmypy daemon" and pass options via command line
4951
50-
This uses the DETACHED_PROCESS flag to invoke the Server.
51-
See https://docs.microsoft.com/en-us/windows/desktop/procthread/process-creation-flags
52+
When creating the daemon grandchild, we create it in a new console, which is
53+
started hidden. We cannot use DETACHED_PROCESS since it will cause console windows
54+
to pop up when starting. See
55+
https://github.com/python/cpython/pull/4150#issuecomment-340215696
56+
for more on why we can't have nice things.
5257
5358
It also pickles the options to be unpickled by mypy.
5459
"""
5560
command = [sys.executable, '-m', 'mypy.dmypy', 'daemon']
5661
pickeled_options = pickle.dumps((options.snapshot(), timeout, log_file))
5762
command.append('--options-data="{}"'.format(base64.b64encode(pickeled_options).decode()))
63+
info = STARTUPINFO(dwFlags=0x1, # STARTF_USESHOWWINDOW aka use wShowWindow's value
64+
wShowWindow=0, # SW_HIDE aka make the window invisible
65+
)
5866
try:
59-
subprocess.Popen(command, creationflags=0x8) # DETACHED_PROCESS
67+
subprocess.Popen(command,
68+
creationflags=0x10, # CREATE_NEW_CONSOLE
69+
startupinfo=info)
6070
return 0
6171
except subprocess.CalledProcessError as e:
6272
return e.returncode

0 commit comments

Comments
 (0)