mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
asyncio: Use the new os.set_blocking() function of Python 3.5 if available
This commit is contained in:
parent
3d4953a14b
commit
f2ed889027
2 changed files with 14 additions and 10 deletions
|
@ -259,10 +259,14 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
|
||||||
return server
|
return server
|
||||||
|
|
||||||
|
|
||||||
def _set_nonblocking(fd):
|
if hasattr(os, 'set_blocking'):
|
||||||
flags = fcntl.fcntl(fd, fcntl.F_GETFL)
|
def _set_nonblocking(fd):
|
||||||
flags = flags | os.O_NONBLOCK
|
os.set_blocking(fd, False)
|
||||||
fcntl.fcntl(fd, fcntl.F_SETFL, flags)
|
else:
|
||||||
|
def _set_nonblocking(fd):
|
||||||
|
flags = fcntl.fcntl(fd, fcntl.F_GETFL)
|
||||||
|
flags = flags | os.O_NONBLOCK
|
||||||
|
fcntl.fcntl(fd, fcntl.F_SETFL, flags)
|
||||||
|
|
||||||
|
|
||||||
class _UnixReadPipeTransport(transports.ReadTransport):
|
class _UnixReadPipeTransport(transports.ReadTransport):
|
||||||
|
|
|
@ -306,9 +306,9 @@ class UnixReadPipeTransportTests(test_utils.TestCase):
|
||||||
self.pipe = mock.Mock(spec_set=io.RawIOBase)
|
self.pipe = mock.Mock(spec_set=io.RawIOBase)
|
||||||
self.pipe.fileno.return_value = 5
|
self.pipe.fileno.return_value = 5
|
||||||
|
|
||||||
fcntl_patcher = mock.patch('fcntl.fcntl')
|
blocking_patcher = mock.patch('asyncio.unix_events._set_nonblocking')
|
||||||
fcntl_patcher.start()
|
blocking_patcher.start()
|
||||||
self.addCleanup(fcntl_patcher.stop)
|
self.addCleanup(blocking_patcher.stop)
|
||||||
|
|
||||||
fstat_patcher = mock.patch('os.fstat')
|
fstat_patcher = mock.patch('os.fstat')
|
||||||
m_fstat = fstat_patcher.start()
|
m_fstat = fstat_patcher.start()
|
||||||
|
@ -469,9 +469,9 @@ class UnixWritePipeTransportTests(test_utils.TestCase):
|
||||||
self.pipe = mock.Mock(spec_set=io.RawIOBase)
|
self.pipe = mock.Mock(spec_set=io.RawIOBase)
|
||||||
self.pipe.fileno.return_value = 5
|
self.pipe.fileno.return_value = 5
|
||||||
|
|
||||||
fcntl_patcher = mock.patch('fcntl.fcntl')
|
blocking_patcher = mock.patch('asyncio.unix_events._set_nonblocking')
|
||||||
fcntl_patcher.start()
|
blocking_patcher.start()
|
||||||
self.addCleanup(fcntl_patcher.stop)
|
self.addCleanup(blocking_patcher.stop)
|
||||||
|
|
||||||
fstat_patcher = mock.patch('os.fstat')
|
fstat_patcher = mock.patch('os.fstat')
|
||||||
m_fstat = fstat_patcher.start()
|
m_fstat = fstat_patcher.start()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue