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:
co-authored by
Claude Opus 4.7
parent
f437b70771
commit
96099feefe
@@ -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)
|
||||
|
||||
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user