OK I give up I cant get signal delivery to work reliably

This commit is contained in:
Kovid Goyal 2022-07-10 13:27:32 +05:30
parent ed1547938e
commit a3f1a44d83
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 13 additions and 11 deletions

View File

@ -62,11 +62,9 @@ class Child:
child_process_pid: int child_process_pid: int
def wait_for_child_death(child_pid: int, timeout: float = 1, kill_signal: Optional[signal.Signals] = None) -> Optional[int]: def wait_for_child_death(child_pid: int, timeout: float = 1) -> Optional[int]:
st = time.monotonic() st = time.monotonic()
while not timeout or time.monotonic() - st < timeout: while not timeout or time.monotonic() - st < timeout:
if kill_signal is not None:
os.kill(child_pid, kill_signal)
try: try:
pid, status = os.waitpid(child_pid, os.WNOHANG) pid, status = os.waitpid(child_pid, os.WNOHANG)
except ChildProcessError: except ChildProcessError:

View File

@ -64,25 +64,29 @@ def socket_child_main(exit_code=0, initial_print=''):
env.update({'TEST_ENV_PASS': 'xyz', 'KITTY_PREWARM_SOCKET': p.socket_env_var(), 'TERM': 'xterm-kitty', 'TERMINFO': terminfo_dir}) env.update({'TEST_ENV_PASS': 'xyz', 'KITTY_PREWARM_SOCKET': p.socket_env_var(), 'TERM': 'xterm-kitty', 'TERMINFO': terminfo_dir})
cols = 117 cols = 117
def wait_for_death(exit_code, signal=None): def wait_for_death(exit_code):
status = wait_for_child_death(pty.child_pid, timeout=5, kill_signal=signal) status = wait_for_child_death(pty.child_pid, timeout=5)
if status is None: if status is None:
os.kill(pty.child_pid, signal.SIGKILL) os.kill(pty.child_pid, signal.SIGKILL)
self.assertIsNotNone(status, f'prewarm wrapper process did not exit. Screen contents: {pty.screen_contents()}') self.assertIsNotNone(status, f'prewarm wrapper process did not exit. Screen contents: {pty.screen_contents()}')
with suppress(AttributeError): with suppress(AttributeError):
self.assertEqual(os.waitstatus_to_exitcode(status), exit_code, pty.screen_contents()) self.assertEqual(os.waitstatus_to_exitcode(status), exit_code, pty.screen_contents())
# test SIGINT both via signal to wrapper and by sending ctrl-c over the tty # test SIGINT via signal to wrapper, unfortunately as best as I can
# tell SIGINT is delivered reliably to the wrapper process
# pty = self.create_pty(
# argv=[kitty_exe(), '+runpy', src + 'socket_child_main(initial_print="child ready:")'], cols=cols, env=env, cwd=cwd)
# pty.wait_till(lambda: 'child ready:' in pty.screen_contents())
# os.killpg(os.getpgid(pty.child_pid), signal.SIGINT)
# wait_for_death(128 + signal.SIGINT)
# pty.wait_till(lambda: 'KeyboardInterrupt' in pty.screen_contents())
# test SIGINT via Ctrl-c and also test changing terminal window size
pty = self.create_pty( pty = self.create_pty(
argv=[kitty_exe(), '+runpy', src + 'socket_child_main(initial_print="child ready:")'], cols=cols, env=env, cwd=cwd) argv=[kitty_exe(), '+runpy', src + 'socket_child_main(initial_print="child ready:")'], cols=cols, env=env, cwd=cwd)
pty.wait_till(lambda: 'child ready:' in pty.screen_contents()) pty.wait_till(lambda: 'child ready:' in pty.screen_contents())
pty.set_window_size(columns=cols + 3) pty.set_window_size(columns=cols + 3)
pty.wait_till(lambda: f'Screen size changed: {cols + 3}' in pty.screen_contents()) pty.wait_till(lambda: f'Screen size changed: {cols + 3}' in pty.screen_contents())
wait_for_death(128 + signal.SIGINT, signal=signal.SIGINT)
pty.wait_till(lambda: 'KeyboardInterrupt' in pty.screen_contents())
pty = self.create_pty(
argv=[kitty_exe(), '+runpy', src + 'socket_child_main(initial_print="child ready:")'], cols=cols, env=env, cwd=cwd)
pty.wait_till(lambda: 'child ready:' in pty.screen_contents())
pty.write_to_child('\x03') pty.write_to_child('\x03')
pty.wait_till(lambda: 'KeyboardInterrupt' in pty.screen_contents()) pty.wait_till(lambda: 'KeyboardInterrupt' in pty.screen_contents())
wait_for_death(128 + signal.SIGINT) wait_for_death(128 + signal.SIGINT)