bpo-31160: Fix race condition in test_os.PtyTests (GH-19263) · python/cpython@16d7567 (original) (raw)
`@@ -1846,6 +1846,7 @@ def run_child(self, child, terminal_input):
`
1846
1846
`os.close(w)
`
1847
1847
`self.skipTest("pty.fork() raised {}".format(e))
`
1848
1848
`raise
`
``
1849
+
1849
1850
`if pid == 0:
`
1850
1851
`# Child
`
1851
1852
`try:
`
`@@ -1859,9 +1860,11 @@ def run_child(self, child, terminal_input):
`
1859
1860
`finally:
`
1860
1861
`# We don't want to return to unittest...
`
1861
1862
`os._exit(0)
`
``
1863
+
1862
1864
`# Parent
`
1863
1865
`os.close(w)
`
1864
1866
`os.write(fd, terminal_input)
`
``
1867
+
1865
1868
`# Get results from the pipe
`
1866
1869
`with open(r, "r") as rpipe:
`
1867
1870
`lines = []
`
`@@ -1871,6 +1874,7 @@ def run_child(self, child, terminal_input):
`
1871
1874
`# The other end was closed => the child exited
`
1872
1875
`break
`
1873
1876
`lines.append(line)
`
``
1877
+
1874
1878
`# Check the result was got and corresponds to the user's terminal input
`
1875
1879
`if len(lines) != 2:
`
1876
1880
`# Something went wrong, try to get at stderr
`
`@@ -1888,11 +1892,14 @@ def run_child(self, child, terminal_input):
`
1888
1892
`child_output = child_output.decode("ascii", "ignore")
`
1889
1893
`self.fail("got %d lines in pipe but expected 2, child output was:\n%s"
`
1890
1894
`% (len(lines), child_output))
`
1891
``
`-
os.close(fd)
`
1892
1895
``
1893
``
`-
Wait until the child process completes
`
``
1896
`+
Wait until the child process completes before closing the PTY to
`
``
1897
`+
prevent sending SIGHUP to the child process.
`
1894
1898
`support.wait_process(pid, exitcode=0)
`
1895
1899
``
``
1900
`+
Close the PTY
`
``
1901
`+
os.close(fd)
`
``
1902
+
1896
1903
`return lines
`
1897
1904
``
1898
1905
`def check_input_tty(self, prompt, terminal_input, stdio_encoding=None):
`