Skip to content

Commit 2b890a5

Browse files
fix(tinytorch): don't use os.kill(pid, 0) as a liveness probe on Windows
The psutil-unavailable fallback in _running_jupyter_pid used os.kill(pid, 0), assuming POSIX signal-0 "probe only" semantics. On Windows, os.kill does not implement that: it calls TerminateProcess for any signal value, including 0. The fallback path meant to check whether a Jupyter server was still running would instead kill it. psutil is already a required project dependency (requirements.txt, tito setup's own package list), so this path should only be reached in a broken environment. Removed the unsafe probe: if psutil can't be imported, treat it the same as "can't tell" and return None, so the caller launches a fresh server instead. Worst case is a duplicate server (the same behavior this PR is fixing in the common case), never silently killing a running one.
1 parent ab82a5e commit 2b890a5

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

tinytorch/tito/commands/module/workflow.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -525,13 +525,16 @@ def _running_jupyter_pid(self) -> Optional[int]:
525525
return None
526526
return pid
527527
except ImportError:
528-
# No psutil available - fall back to os-level existence check only,
529-
# which can't verify it's still actually a Jupyter process.
530-
try:
531-
os.kill(pid, 0)
532-
return pid
533-
except OSError:
534-
return None
528+
# No psutil available. Deliberately not falling back to an
529+
# os.kill(pid, 0) "probe" here: on Windows, os.kill does not
530+
# implement POSIX signal-0 semantics -- it calls TerminateProcess
531+
# for any signal value, so "checking" whether the PID is alive
532+
# would actually kill it. psutil is already a required project
533+
# dependency (requirements.txt, tito setup), so this should only
534+
# happen in a broken environment; treat it the same as "can't
535+
# tell" and let the caller launch a fresh server. Worst case is
536+
# a duplicate server, not silently killing a running one.
537+
return None
535538
except Exception:
536539
return None
537540

0 commit comments

Comments
 (0)