Skip to content

Commit d76b74e

Browse files
committed
Debug startup errors on Windows
1 parent 5e2ef78 commit d76b74e

4 files changed

Lines changed: 14 additions & 2 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ jobs:
116116
python: '3.14'
117117
os: windows-latest
118118
toxenv: py
119-
tox_extra_args: "-n 2 --mypy-num-workers=2 mypy/test/testcheck.py -k 'incremental or modules or classes'"
119+
tox_extra_args: "-n 4 --mypy-num-workers=2 mypy/test/testcheck.py"
120120

121121
- name: Type check our own code (py310-ubuntu)
122122
python: '3.10'

mypy/build.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ def __init__(self, status_file: str, options_data: str, env: Mapping[str, str])
283283
]
284284
# Return early without waiting, caller must call connect() before using the client.
285285
self.proc = subprocess.Popen(command, env=env)
286+
self.connected = False
286287

287288
def connect(self) -> None:
288289
end_time = time.time() + WORKER_START_TIMEOUT
@@ -303,12 +304,12 @@ def connect(self) -> None:
303304
# verify PIDs reliably.
304305
assert pid == self.proc.pid, f"PID mismatch: {pid} vs {self.proc.pid}"
305306
self.conn = IPCClient(connection_name, WORKER_CONNECTION_TIMEOUT)
307+
self.connected = True
306308
return
307309
except Exception as exc:
308310
last_exception = exc
309311
break
310312
print("Failed to establish connection with worker:", last_exception)
311-
sys.exit(2)
312313

313314
def close(self) -> None:
314315
self.conn.close()
@@ -394,6 +395,8 @@ def default_flush_errors(
394395
def connect(wc: WorkerClient, data: bytes) -> None:
395396
# Start loading sources in each worker as soon as it is up.
396397
wc.connect()
398+
if not wc.connected:
399+
return
397400
wc.conn.write_bytes(data)
398401

399402
# We don't wait for workers to be ready until they are actually needed.
@@ -432,6 +435,8 @@ def connect(wc: WorkerClient, data: bytes) -> None:
432435
for thread in connect_threads:
433436
thread.join()
434437
for worker in workers:
438+
if not worker.connected:
439+
continue
435440
try:
436441
send(worker.conn, SccRequestMessage(scc_id=None, import_errors={}, mod_data={}))
437442
except (OSError, IPCException):
@@ -3972,6 +3977,8 @@ def dispatch(
39723977
# Wait for workers since they may be needed at this point.
39733978
for thread in connect_threads:
39743979
thread.join()
3980+
if not all(wc.connected for wc in manager.workers):
3981+
raise OSError("Build workers failed to start")
39753982
process_graph(graph, manager)
39763983
# Update plugins snapshot.
39773984
write_plugins_snapshot(manager)

mypy/build_worker/worker.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ def main(argv: list[str]) -> None:
9494
status_file = args.status_file
9595
server = IPCServer(CONNECTION_NAME, WORKER_CONNECTION_TIMEOUT)
9696

97+
if sys.platform == "win32":
98+
print("Writing status file:", status_file)
99+
97100
try:
98101
with open(status_file, "w") as f:
99102
json.dump({"pid": os.getpid(), "connection_name": server.connection_name}, f)

mypy/ipc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ def read_status(status_file: str) -> dict[str, object]:
361361
Raise BadStatus if the status file doesn't exist or contains
362362
invalid JSON or the JSON is not a dict.
363363
"""
364+
if sys.platform == "win32":
365+
print("Reading status file:", status_file)
364366
if not os.path.isfile(status_file):
365367
raise BadStatus("No status file found")
366368
with open(status_file) as f:

0 commit comments

Comments
 (0)