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
)
| 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 | |
| 75 | else: |
| 76 |
no test coverage detected
searching dependent graphs…