diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-07-29 20:32:47 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-07-29 20:32:47 (GMT) |
commit | 1db9e7bb19909ed56821b1580cbb024faccac041 (patch) | |
tree | 20043197ec08844340c9ac039fe26c630bd4189d /Lib/test/test_pty.py | |
parent | 6aa4269ed25f7fdddd99fe1d7b09b8406ecb05ea (diff) | |
download | cpython-1db9e7bb19909ed56821b1580cbb024faccac041.zip cpython-1db9e7bb19909ed56821b1580cbb024faccac041.tar.gz cpython-1db9e7bb19909ed56821b1580cbb024faccac041.tar.bz2 |
Issue #22054: Add os.get_blocking() and os.set_blocking() functions to get and
set the blocking mode of a file descriptor (False if the O_NONBLOCK flag is
set, True otherwise). These functions are not available on Windows.
Diffstat (limited to 'Lib/test/test_pty.py')
-rw-r--r-- | Lib/test/test_pty.py | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py index 8916861..9b783c3 100644 --- a/Lib/test/test_pty.py +++ b/Lib/test/test_pty.py @@ -1,7 +1,6 @@ from test.support import verbose, run_unittest, import_module, reap_children -#Skip these tests if either fcntl or termios is not available -fcntl = import_module('fcntl') +# Skip these tests if termios is not available import_module('termios') import errno @@ -84,16 +83,18 @@ class PtyTest(unittest.TestCase): # in master_open(), we need to read the EOF. # Ensure the fd is non-blocking in case there's nothing to read. - orig_flags = fcntl.fcntl(master_fd, fcntl.F_GETFL) - fcntl.fcntl(master_fd, fcntl.F_SETFL, orig_flags | os.O_NONBLOCK) + blocking = os.get_blocking(master_fd) try: - s1 = os.read(master_fd, 1024) - self.assertEqual(b'', s1) - except OSError as e: - if e.errno != errno.EAGAIN: - raise - # Restore the original flags. - fcntl.fcntl(master_fd, fcntl.F_SETFL, orig_flags) + os.set_blocking(master_fd, False) + try: + s1 = os.read(master_fd, 1024) + self.assertEqual(b'', s1) + except OSError as e: + if e.errno != errno.EAGAIN: + raise + finally: + # Restore the original flags. + os.set_blocking(master_fd, blocking) debug("Writing to slave_fd") os.write(slave_fd, TEST_STRING_1) |