diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-12-09 03:15:07 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-09 03:15:07 -0800 |
| commit | b9f4b49c6e525afd6fce02cfc14be52e98a18f67 (patch) | |
| tree | 09d3b7cd3015fff0b942113eae7fca928c24f82a | |
| parent | 41973c99fdfdc78315e819661e279bdcc2f058b1 (diff) | |
| download | cpython-git-b9f4b49c6e525afd6fce02cfc14be52e98a18f67.tar.gz | |
bpo-38547: Fix test_pty if the process is the session leader (GH-17519)
Fix test_pty: if the process is the session leader, closing the
master file descriptor raises a SIGHUP signal: simply ignore SIGHUP
when running the tests.
(cherry picked from commit a1838ec2592e5082c75c77888f2a7a3eb21133e5)
Co-authored-by: Victor Stinner <vstinner@python.org>
| -rw-r--r-- | Lib/test/test_pty.py | 19 | ||||
| -rw-r--r-- | Misc/NEWS.d/next/Tests/2019-12-09-11-32-34.bpo-38547.Juw54e.rst | 3 |
2 files changed, 19 insertions, 3 deletions
diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py index 3b448569a2..ce85f575a0 100644 --- a/Lib/test/test_pty.py +++ b/Lib/test/test_pty.py @@ -66,16 +66,27 @@ def _readline(fd): # XXX(nnorwitz): these tests leak fds when there is an error. class PtyTest(unittest.TestCase): def setUp(self): - # isatty() and close() can hang on some platforms. Set an alarm - # before running the test to make sure we don't hang forever. old_alarm = signal.signal(signal.SIGALRM, self.handle_sig) 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) + + # isatty() and close() can hang on some platforms. Set an alarm + # before running the test to make sure we don't hang forever. self.addCleanup(signal.alarm, 0) signal.alarm(10) def handle_sig(self, sig, frame): self.fail("isatty hung") + @staticmethod + def handle_sighup(sig, frame): + # 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 + def test_basic(self): try: debug("Calling master_open()") @@ -122,9 +133,11 @@ class PtyTest(unittest.TestCase): self.assertEqual(b'For my pet fish, Eric.\n', normalize_output(s2)) os.close(slave_fd) + # closing master_fd can raise a SIGHUP if the process is + # the session leader: we installed a SIGHUP signal handler + # to ignore this signal. os.close(master_fd) - def test_fork(self): debug("calling pty.fork()") pid, master_fd = pty.fork() diff --git a/Misc/NEWS.d/next/Tests/2019-12-09-11-32-34.bpo-38547.Juw54e.rst b/Misc/NEWS.d/next/Tests/2019-12-09-11-32-34.bpo-38547.Juw54e.rst new file mode 100644 index 0000000000..10f3cc0851 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2019-12-09-11-32-34.bpo-38547.Juw54e.rst @@ -0,0 +1,3 @@ +Fix test_pty: if the process is the session leader, closing the master file +descriptor raises a SIGHUP signal: simply ignore SIGHUP when running the +tests. |
