"""Tests that use a pseudo terminal to guarantee stdin and stdout are
terminals in the test environment"""
+ @staticmethod
+ def handle_sighup(signum, frame):
+ # bpo-40140: if the process is the session leader, os.close(fd)
+ # of "pid, fd = pty.fork()" can raise SIGHUP signal:
+ # just ignore the signal.
+ pass
+
def run_child(self, child, terminal_input):
+ old_sighup = signal.signal(signal.SIGHUP, self.handle_sighup)
+ try:
+ return self._run_child(child, terminal_input)
+ finally:
+ signal.signal(signal.SIGHUP, old_sighup)
+
+ def _run_child(self, child, terminal_input):
r, w = os.pipe() # Pipe test results from child back to parent
try:
pid, fd = pty.fork()
child_output = child_output.decode("ascii", "ignore")
self.fail("got %d lines in pipe but expected 2, child output was:\n%s"
% (len(lines), child_output))
+
+ # bpo-40155: Close the PTY before waiting for the child process
+ # completion, otherwise the child process hangs on AIX.
os.close(fd)
# Wait until the child process completes
self.addCleanup(signal.signal, signal.SIGALRM, old_alarm)
old_sighup = signal.signal(signal.SIGHUP, self.handle_sighup)
- self.addCleanup(signal.signal, signal.SIGHUP, old_alarm)
+ self.addCleanup(signal.signal, signal.SIGHUP, old_sighup)
# isatty() and close() can hang on some platforms. Set an alarm
# before running the test to make sure we don't hang forever.
self.fail("isatty hung")
@staticmethod
- def handle_sighup(sig, frame):
- # if the process is the session leader, os.close(master_fd)
+ def handle_sighup(signum, frame):
+ # bpo-38547: if the process is the session leader, os.close(master_fd)
# of "master_fd, slave_name = pty.master_open()" raises SIGHUP
# signal: just ignore the signal.
pass