bpo-40140: test_builtin.PtyTests registers SIGHUP handler (GH-19314) · python/cpython@7a51a7e (original) (raw)
`@@ -1837,7 +1837,21 @@ class PtyTests(unittest.TestCase):
`
1837
1837
`"""Tests that use a pseudo terminal to guarantee stdin and stdout are
`
1838
1838
` terminals in the test environment"""
`
1839
1839
``
``
1840
`+
@staticmethod
`
``
1841
`+
def handle_sighup(signum, frame):
`
``
1842
`+
bpo-40140: if the process is the session leader, os.close(fd)
`
``
1843
`+
of "pid, fd = pty.fork()" can raise SIGHUP signal:
`
``
1844
`+
just ignore the signal.
`
``
1845
`+
pass
`
``
1846
+
1840
1847
`def run_child(self, child, terminal_input):
`
``
1848
`+
old_sighup = signal.signal(signal.SIGHUP, self.handle_sighup)
`
``
1849
`+
try:
`
``
1850
`+
return self._run_child(child, terminal_input)
`
``
1851
`+
finally:
`
``
1852
`+
signal.signal(signal.SIGHUP, old_sighup)
`
``
1853
+
``
1854
`+
def _run_child(self, child, terminal_input):
`
1841
1855
`r, w = os.pipe() # Pipe test results from child back to parent
`
1842
1856
`try:
`
1843
1857
`pid, fd = pty.fork()
`
`@@ -1893,13 +1907,12 @@ def run_child(self, child, terminal_input):
`
1893
1907
`self.fail("got %d lines in pipe but expected 2, child output was:\n%s"
`
1894
1908
`% (len(lines), child_output))
`
1895
1909
``
1896
``
`-
Wait until the child process completes before closing the PTY to
`
1897
``
`-
prevent sending SIGHUP to the child process.
`
1898
``
`-
support.wait_process(pid, exitcode=0)
`
1899
``
-
1900
``
`-
Close the PTY
`
``
1910
`+
bpo-40155: Close the PTY before waiting for the child process
`
``
1911
`+
completion, otherwise the child process hangs on AIX.
`
1901
1912
`os.close(fd)
`
1902
1913
``
``
1914
`+
support.wait_process(pid, exitcode=0)
`
``
1915
+
1903
1916
`return lines
`
1904
1917
``
1905
1918
`def check_input_tty(self, prompt, terminal_input, stdio_encoding=None):
`