MCPcopy Index your code
hub / github.com/python/mypy / daemonize

Function daemonize

mypy/dmypy_server.py:46–73  ·  view source on GitHub ↗

Create the daemon process via "dmypy daemon" and pass options via command line When creating the daemon grandchild, we create it in a new console, which is started hidden. We cannot use DETACHED_PROCESS since it will cause console windows to pop up when starting. See

(
        options: Options, status_file: str, timeout: int | None = None, log_file: str | None = None
    )

Source from the content-addressed store, hash-verified

44 from subprocess import STARTUPINFO
45
46 def daemonize(
47 options: Options, status_file: str, timeout: int | None = None, log_file: str | None = None
48 ) -> int:
49 """Create the daemon process via "dmypy daemon" and pass options via command line
50
51 When creating the daemon grandchild, we create it in a new console, which is
52 started hidden. We cannot use DETACHED_PROCESS since it will cause console windows
53 to pop up when starting. See
54 https://github.com/python/cpython/pull/4150#issuecomment-340215696
55 for more on why we can't have nice things.
56
57 It also pickles the options to be unpickled by mypy.
58 """
59 command = [sys.executable, "-m", "mypy.dmypy", "--status-file", status_file, "daemon"]
60 pickled_options = pickle.dumps(options.snapshot())
61 command.append(f'--options-data="{b64encode(pickled_options).decode()}"')
62 if timeout:
63 command.append(f"--timeout={timeout}")
64 if log_file:
65 command.append(f"--log-file={log_file}")
66 info = STARTUPINFO()
67 info.dwFlags = 0x1 # STARTF_USESHOWWINDOW aka use wShowWindow's value
68 info.wShowWindow = 0 # SW_HIDE aka make the window invisible
69 try:
70 subprocess.Popen(command, creationflags=0x10, startupinfo=info) # CREATE_NEW_CONSOLE
71 return 0
72 except subprocess.CalledProcessError as e:
73 return e.returncode
74
75else:
76

Callers 1

start_serverFunction · 0.90

Calls 6

_daemonize_cbFunction · 0.85
ServerClass · 0.85
dumpsMethod · 0.80
snapshotMethod · 0.80
appendMethod · 0.80
decodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…