summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-07-29 22:45:43 +0200
committerVictor Stinner <victor.stinner@gmail.com>2014-07-29 22:45:43 +0200
commitfb9baae7d3fa933d6748c96e768edb47e27aade7 (patch)
treebb6fc0d0592ad515b540d3d0e01eef6ef77ce4d7
parent3ed8be38d2b9936a0c2c8474fe1d217e02918ae8 (diff)
downloadtrollius-fb9baae7d3fa933d6748c96e768edb47e27aade7.tar.gz
Use the new os.set_blocking() function of Python 3.5 if available
-rw-r--r--asyncio/unix_events.py12
-rw-r--r--tests/test_unix_events.py12
2 files changed, 14 insertions, 10 deletions
diff --git a/asyncio/unix_events.py b/asyncio/unix_events.py
index 5020cc5..8d3e25e 100644
--- a/asyncio/unix_events.py
+++ b/asyncio/unix_events.py
@@ -259,10 +259,14 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
return server
-def _set_nonblocking(fd):
- flags = fcntl.fcntl(fd, fcntl.F_GETFL)
- flags = flags | os.O_NONBLOCK
- fcntl.fcntl(fd, fcntl.F_SETFL, flags)
+if hasattr(os, 'set_blocking'):
+ def _set_nonblocking(fd):
+ os.set_blocking(fd, False)
+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):
diff --git a/tests/test_unix_events.py b/tests/test_unix_events.py
index 099d4d5..e397598 100644
--- a/tests/test_unix_events.py
+++ b/tests/test_unix_events.py
@@ -306,9 +306,9 @@ class UnixReadPipeTransportTests(test_utils.TestCase):
self.pipe = mock.Mock(spec_set=io.RawIOBase)
self.pipe.fileno.return_value = 5
- fcntl_patcher = mock.patch('fcntl.fcntl')
- fcntl_patcher.start()
- self.addCleanup(fcntl_patcher.stop)
+ blocking_patcher = mock.patch('asyncio.unix_events._set_nonblocking')
+ blocking_patcher.start()
+ self.addCleanup(blocking_patcher.stop)
fstat_patcher = mock.patch('os.fstat')
m_fstat = fstat_patcher.start()
@@ -469,9 +469,9 @@ class UnixWritePipeTransportTests(test_utils.TestCase):
self.pipe = mock.Mock(spec_set=io.RawIOBase)
self.pipe.fileno.return_value = 5
- fcntl_patcher = mock.patch('fcntl.fcntl')
- fcntl_patcher.start()
- self.addCleanup(fcntl_patcher.stop)
+ blocking_patcher = mock.patch('asyncio.unix_events._set_nonblocking')
+ blocking_patcher.start()
+ self.addCleanup(blocking_patcher.stop)
fstat_patcher = mock.patch('os.fstat')
m_fstat = fstat_patcher.start()