[Python-checkins] cpython (merge 3.5 -> default): Merge 3.5 (asyncio)

victor.stinner python-checkins at python.org
Fri Apr 1 15:41:05 EDT 2016


https://hg.python.org/cpython/rev/e3ecbac90eaf
changeset:   100823:e3ecbac90eaf
parent:      100820:3d6b67361749
parent:      100822:6dc33c07e517
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Fri Apr 01 21:40:14 2016 +0200
summary:
  Merge 3.5 (asyncio)

files:
  Lib/asyncio/tasks.py                |  14 ++++++++------
  Lib/test/test_asyncio/test_tasks.py |  16 ++++++++++++++++
  Modules/overlapped.c                |   6 ++++++
  3 files changed, 30 insertions(+), 6 deletions(-)


diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -401,7 +401,7 @@
 
 @coroutine
 def _wait(fs, timeout, return_when, loop):
-    """Internal helper for wait() and _wait_for().
+    """Internal helper for wait() and wait_for().
 
     The fs argument must be a collection of Futures.
     """
@@ -747,7 +747,7 @@
     ...     yield from coro()
 
 
-    timeout: timeout value in seconds
+    timeout: timeout value in seconds or None to disable timeout logic
     loop: asyncio compatible event loop
     """
     if loop is None:
@@ -768,8 +768,9 @@
         if self._task is None:
             raise RuntimeError('Timeout context manager should be used '
                                'inside a task')
-        self._cancel_handler = self._loop.call_later(
-            self._timeout, self._cancel_task)
+        if self._timeout is not None:
+            self._cancel_handler = self._loop.call_later(
+                self._timeout, self._cancel_task)
         return self
 
     def __exit__(self, exc_type, exc_val, exc_tb):
@@ -777,8 +778,9 @@
             self._cancel_handler = None
             self._task = None
             raise futures.TimeoutError
-        self._cancel_handler.cancel()
-        self._cancel_handler = None
+        if self._timeout is not None:
+            self._cancel_handler.cancel()
+            self._cancel_handler = None
         self._task = None
 
     def _cancel_task(self):
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -2382,6 +2382,22 @@
 
         self.loop.run_until_complete(go())
 
+    def test_timeout_disable(self):
+        @asyncio.coroutine
+        def long_running_task():
+            yield from asyncio.sleep(0.1, loop=self.loop)
+            return 'done'
+
+        @asyncio.coroutine
+        def go():
+            t0 = self.loop.time()
+            with asyncio.timeout(None, loop=self.loop):
+                resp = yield from long_running_task()
+            self.assertEqual(resp, 'done')
+            dt = self.loop.time() - t0
+            self.assertTrue(0.09 < dt < 0.11, dt)
+        self.loop.run_until_complete(go())
+
     def test_raise_runtimeerror_if_no_task(self):
         with self.assertRaises(RuntimeError):
             with asyncio.timeout(0.1, loop=self.loop):
diff --git a/Modules/overlapped.c b/Modules/overlapped.c
--- a/Modules/overlapped.c
+++ b/Modules/overlapped.c
@@ -23,6 +23,12 @@
 #  define T_POINTER T_ULONGLONG
 #endif
 
+/* Compatibility with Python 3.3 */
+#if PY_VERSION_HEX < 0x03040000
+#    define PyMem_RawMalloc PyMem_Malloc
+#    define PyMem_RawFree PyMem_Free
+#endif
+
 #define F_HANDLE F_POINTER
 #define F_ULONG_PTR F_POINTER
 #define F_DWORD "k"

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list