fix: reap and capture exit status in terminate; test exit_code

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Rohit Mahto
2026-05-23 12:53:16 +05:30
co-authored by Claude Opus 4.7
parent f437b70771
commit 96099feefe
2 changed files with 10 additions and 0 deletions
+9
View File
@@ -102,6 +102,15 @@ class _UnixPty:
os.kill(self.pid, signal.SIGKILL)
except OSError:
pass
try: # reap immediately and capture the exit status
wpid, status = os.waitpid(self.pid, 0)
if wpid == self.pid:
if os.WIFEXITED(status):
self._exit_code = os.WEXITSTATUS(status)
elif os.WIFSIGNALED(status):
self._exit_code = -os.WTERMSIG(status)
except OSError:
pass
if self.fd is not None:
try:
os.close(self.fd)
+1
View File
@@ -60,6 +60,7 @@ def test_terminate_stops_session():
while s.is_alive() and time.time() < deadline:
time.sleep(0.05)
assert s.is_alive() is False
assert s.exit_code() == -9 # killed by SIGKILL
def test_resize_applies_to_pty():