diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-09-27 23:38:55 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-09-27 23:38:55 +0200 |
| commit | 19c1e280cbbfc83f0c2cbadadc8e0fb692d8dd70 (patch) | |
| tree | c0e80e0746a96b8dfb9f6ecf1f04505c35aafadd /packages/meshbay-node/src | |
| parent | 6c7b61a8e946b777ea1985058dbed9019bddd53a (diff) | |
| download | meshbay-19c1e280cbbfc83f0c2cbadadc8e0fb692d8dd70.tar.gz | |
fix(node): tell whether a pid is alive on Linux too
_pid_alive only ran tasklist, so request_graceful_stop raised
FileNotFoundError off Windows and two real-daemon tests failed on Linux.
Read /proc there, counting a zombie as gone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-node/src')
| -rw-r--r-- | packages/meshbay-node/src/meshbay_node/platform.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/platform.py b/packages/meshbay-node/src/meshbay_node/platform.py index 09397a2..2255036 100644 --- a/packages/meshbay-node/src/meshbay_node/platform.py +++ b/packages/meshbay-node/src/meshbay_node/platform.py @@ -226,6 +226,14 @@ def _startup_vbs() -> Path: def _pid_alive(pid: int) -> bool: """Whether a process with this pid exists, in any session (tasklist lists session 0 too, where a service-mode daemon runs; opening it would not).""" + if sys.platform != "win32": + # A zombie counts as gone: it has exited, and only its parent has not + # reaped it yet -- os.kill(pid, 0) would still find it. + try: + stat = Path(f"/proc/{pid}/stat").read_text(encoding="ascii") + except OSError: + return False + return stat.rsplit(")", 1)[1].split()[0] != "Z" r = subprocess.run(["tasklist", "/FI", f"PID eq {pid}", "/NH", "/FO", "CSV"], capture_output=True, text=True) return f'"{pid}"' in r.stdout |