fix(pty-bridge): terminate PTY process groups on teardown

This commit is contained in:
paulb26
2026-06-08 07:03:12 -07:00
committed by Teknium
parent e9c1e757fe
commit b31c6c33b2
2 changed files with 82 additions and 2 deletions
+12 -2
View File
@@ -250,13 +250,23 @@ class PtyBridge:
return
self._closed = True
try:
pgid = os.getpgid(self._proc.pid)
except Exception:
pgid = None
# SIGHUP is the conventional "your terminal went away" signal.
# We escalate if the child ignores it.
# Send it to the whole foreground process group, not just the PTY
# leader: the dashboard TUI starts helper children such as the Python
# slash worker, and killing only the leader can strand those helpers.
for sig in (signal.SIGHUP, signal.SIGTERM, signal.SIGKILL): # windows-footgun: ok — POSIX-only module (imports fcntl/termios/ptyprocess at top)
if not self._proc.isalive():
break
try:
self._proc.kill(sig)
if pgid is not None:
os.killpg(pgid, sig)
else:
self._proc.kill(sig)
except Exception:
pass
deadline = time.monotonic() + 0.5