Skip to content

[3.7] bpo-38547: Fix test_pty if the process is the session leader (GH-17519) #17521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions Lib/test/test_pty.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()")
Expand Down Expand Up @@ -122,9 +133,11 @@ def test_basic(self):
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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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.