[Python-checkins] cpython (3.4): Issue #20505: BaseEventLoop uses again the resolution of the clock to decide if

larry.hastings python-checkins at python.org
Mon Mar 17 07:31:19 CET 2014


http://hg.python.org/cpython/rev/6733d9dfffbb
changeset:   89695:6733d9dfffbb
branch:      3.4
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Mon Feb 10 23:42:32 2014 +0100
summary:
  Issue #20505: BaseEventLoop uses again the resolution of the clock to decide if
scheduled tasks should be executed or not.

files:
  Lib/asyncio/base_events.py           |   5 +++--
  Lib/test/test_asyncio/test_events.py |  12 ++++++------
  2 files changed, 9 insertions(+), 8 deletions(-)


diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -96,6 +96,7 @@
         self._default_executor = None
         self._internal_fds = 0
         self._running = False
+        self._clock_resolution = time.get_clock_info('monotonic').resolution
 
     def _make_socket_transport(self, sock, protocol, waiter=None, *,
                                extra=None, server=None):
@@ -643,10 +644,10 @@
         self._process_events(event_list)
 
         # Handle 'later' callbacks that are ready.
-        now = self.time()
+        end_time = self.time() + self._clock_resolution
         while self._scheduled:
             handle = self._scheduled[0]
-            if handle._when > now:
+            if handle._when >= end_time:
                 break
             handle = heapq.heappop(self._scheduled)
             self._ready.append(handle)
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -1178,15 +1178,15 @@
             yield from asyncio.sleep(1e-4, loop=loop)
             yield from asyncio.sleep(1e-6, loop=loop)
             yield from asyncio.sleep(1e-8, loop=loop)
+            yield from asyncio.sleep(1e-10, loop=loop)
 
         self.loop.run_until_complete(wait())
-        # The ideal number of call is 10, but on some platforms, the selector
+        # The ideal number of call is 12, but on some platforms, the selector
         # may sleep at little bit less than timeout depending on the resolution
-        # of the clock used by the kernel. Tolerate 5 useless calls on these
-        # platforms.
-        self.assertLessEqual(self.loop._run_once_counter, 15,
-            {'time_info': time.get_clock_info('time'),
-             'monotonic_info': time.get_clock_info('monotonic'),
+        # of the clock used by the kernel. Tolerate a few useless calls on
+        # these platforms.
+        self.assertLessEqual(self.loop._run_once_counter, 20,
+            {'clock_resolution': self.loop._clock_resolution,
              'selector': self.loop._selector.__class__.__name__})
 
 

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


More information about the Python-checkins mailing list