summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-01-25 14:01:33 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-01-25 14:01:33 (GMT)
commitf67255ab94742b017697bdedfd4c8eb25dac6f82 (patch)
tree391dc1e1c5a305ae4cc9bccec135a9bb6206e37f /Lib/asyncio
parent635fca9704b102a97233a3af18231a7b649d0169 (diff)
downloadcpython-f67255ab94742b017697bdedfd4c8eb25dac6f82.zip
cpython-f67255ab94742b017697bdedfd4c8eb25dac6f82.tar.gz
cpython-f67255ab94742b017697bdedfd4c8eb25dac6f82.tar.bz2
Issue #20311: asyncio: Add a granularity attribute to BaseEventLoop: maximum
between the resolution of the BaseEventLoop.time() method and the resolution of the selector. The granuarility is used in the scheduler to round time and deadline.
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/base_events.py6
-rw-r--r--Lib/asyncio/selector_events.py1
2 files changed, 7 insertions, 0 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 72201aa..d082bcc 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -18,6 +18,7 @@ import collections
import concurrent.futures
import heapq
import logging
+import math
import socket
import subprocess
import time
@@ -96,6 +97,7 @@ class BaseEventLoop(events.AbstractEventLoop):
self._default_executor = None
self._internal_fds = 0
self._running = False
+ self.granularity = time.get_clock_info('monotonic').resolution
def _make_socket_transport(self, sock, protocol, waiter=None, *,
extra=None, server=None):
@@ -603,6 +605,8 @@ class BaseEventLoop(events.AbstractEventLoop):
elif self._scheduled:
# Compute the desired timeout.
when = self._scheduled[0]._when
+ # round deadline aways from zero
+ when = math.ceil(when / self.granularity) * self.granularity
deadline = max(0, when - self.time())
if timeout is None:
timeout = deadline
@@ -629,6 +633,8 @@ class BaseEventLoop(events.AbstractEventLoop):
# Handle 'later' callbacks that are ready.
now = self.time()
+ # round current time aways from zero
+ now = math.ceil(now / self.granularity) * self.granularity
while self._scheduled:
handle = self._scheduled[0]
if handle._when > now:
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
index 19caf79..d2b3ccc 100644
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -34,6 +34,7 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
selector = selectors.DefaultSelector()
logger.debug('Using selector: %s', selector.__class__.__name__)
self._selector = selector
+ self.granularity = max(selector.resolution, self.granularity)
self._make_self_pipe()
def _make_socket_transport(self, sock, protocol, waiter=None, *,