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.
This commit is contained in:
Victor Stinner 2014-07-29 22:32:47 +02:00
parent 6aa4269ed2
commit 1db9e7bb19
13 changed files with 198 additions and 58 deletions

View file

@ -276,7 +276,6 @@ class WakeupSignalTests(unittest.TestCase):
# use a subprocess to have only one thread
code = """if 1:
import _testcapi
import fcntl
import os
import signal
import struct
@ -299,10 +298,7 @@ class WakeupSignalTests(unittest.TestCase):
signal.signal(signal.SIGALRM, handler)
read, write = os.pipe()
for fd in (read, write):
flags = fcntl.fcntl(fd, fcntl.F_GETFL, 0)
flags = flags | os.O_NONBLOCK
fcntl.fcntl(fd, fcntl.F_SETFL, flags)
os.set_blocking(write, False)
signal.set_wakeup_fd(write)
test()
@ -322,7 +318,6 @@ class WakeupSignalTests(unittest.TestCase):
code = """if 1:
import _testcapi
import errno
import fcntl
import os
import signal
import sys
@ -333,8 +328,7 @@ class WakeupSignalTests(unittest.TestCase):
signal.signal(signal.SIGALRM, handler)
r, w = os.pipe()
flags = fcntl.fcntl(r, fcntl.F_GETFL, 0)
fcntl.fcntl(r, fcntl.F_SETFL, flags | os.O_NONBLOCK)
os.set_blocking(r, False)
# Set wakeup_fd a read-only file descriptor to trigger the error
signal.set_wakeup_fd(r)