summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-02-10 23:55:47 +0100
committerVictor Stinner <victor.stinner@gmail.com>2014-02-10 23:55:47 +0100
commitd8f1249230196cfaa4dd6429cab603610501abea (patch)
tree9f092a4fe5dcdef85e3a1946637e7d87d6670610
parent40423b1e738481a4732eb26601f29356a43c72a5 (diff)
downloadtrollius-d8f1249230196cfaa4dd6429cab603610501abea.tar.gz
Python issue #20505: BaseEventLoop uses again the resolution of the clock to
decide if scheduled tasks should be executed or not.
-rw-r--r--asyncio/base_events.py11
-rw-r--r--tests/test_events.py13
2 files changed, 18 insertions, 6 deletions
diff --git a/asyncio/base_events.py b/asyncio/base_events.py
index 558406c..377ea21 100644
--- a/asyncio/base_events.py
+++ b/asyncio/base_events.py
@@ -96,6 +96,7 @@ class BaseEventLoop(events.AbstractEventLoop):
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):
@@ -633,14 +634,20 @@ class BaseEventLoop(events.AbstractEventLoop):
else:
logger.log(level, 'poll took %.3f seconds', t1-t0)
else:
+ t0 = self.time()
event_list = self._selector.select(timeout)
+ dt = self.time() - t0
+ if not event_list and timeout and dt < timeout:
+ print("asyncio: selector.select(%.3f ms) took %.3f ms"
+ % (timeout*1e3, dt*1e3),
+ file=sys.__stderr__, flush=True)
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/tests/test_events.py b/tests/test_events.py
index 4fb4b25..3f99da4 100644
--- a/tests/test_events.py
+++ b/tests/test_events.py
@@ -1176,13 +1176,18 @@ class EventLoopTestsMixin:
loop = self.loop
yield from asyncio.sleep(1e-2, loop=loop)
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 6, 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 2 useless calls on these
- # platforms.
- self.assertLessEqual(self.loop._run_once_counter, 8)
+ # 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__})
class SubprocessTestsMixin: