@@ -1790,7 +1790,21 @@ class PtyTests(unittest.TestCase): |
|
|
1790 |
1790 |
"""Tests that use a pseudo terminal to guarantee stdin and stdout are |
1791 |
1791 |
terminals in the test environment""" |
1792 |
1792 |
|
|
1793 |
+@staticmethod |
|
1794 |
+def handle_sighup(signum, frame): |
|
1795 |
+# bpo-40140: if the process is the session leader, os.close(fd) |
|
1796 |
+# of "pid, fd = pty.fork()" can raise SIGHUP signal: |
|
1797 |
+# just ignore the signal. |
|
1798 |
+pass |
|
1799 |
+ |
1793 |
1800 |
def run_child(self, child, terminal_input): |
|
1801 |
+old_sighup = signal.signal(signal.SIGHUP, self.handle_sighup) |
|
1802 |
+try: |
|
1803 |
+return self._run_child(child, terminal_input) |
|
1804 |
+finally: |
|
1805 |
+signal.signal(signal.SIGHUP, old_sighup) |
|
1806 |
+ |
|
1807 |
+def _run_child(self, child, terminal_input): |
1794 |
1808 |
r, w = os.pipe() # Pipe test results from child back to parent |
1795 |
1809 |
try: |
1796 |
1810 |
pid, fd = pty.fork() |
@@ -1841,6 +1855,9 @@ def run_child(self, child, terminal_input): |
|
|
1841 |
1855 |
child_output = child_output.decode("ascii", "ignore") |
1842 |
1856 |
self.fail("got %d lines in pipe but expected 2, child output was:\n%s" |
1843 |
1857 |
% (len(lines), child_output)) |
|
1858 |
+ |
|
1859 |
+# bpo-40155: Close the PTY before waiting for the child process |
|
1860 |
+# completion, otherwise the child process hangs on AIX. |
1844 |
1861 |
os.close(fd) |
1845 |
1862 |
|
1846 |
1863 |
# Wait until the child process completes |