summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-01-25 23:02:31 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-01-25 23:02:31 (GMT)
commit669eeaf9339a4096db0e5566b4c986300cb60f00 (patch)
tree4b286f6acb2233d518b9e6a69e434c3f0e2c3a7e /Lib
parent3c2f175ec4355a0e1f3e4d7c21ff3986e8d93dc8 (diff)
downloadcpython-669eeaf9339a4096db0e5566b4c986300cb60f00.zip
cpython-669eeaf9339a4096db0e5566b4c986300cb60f00.tar.gz
cpython-669eeaf9339a4096db0e5566b4c986300cb60f00.tar.bz2
Merge latest Tulip into asyncio
- Make the new granularity attribute private - Simplify BaseEventLoop._run_once(): avoid math.ceil(), use simple arithmetic instead
Diffstat (limited to 'Lib')
-rw-r--r--Lib/asyncio/base_events.py9
-rw-r--r--Lib/asyncio/selector_events.py2
-rw-r--r--Lib/test/test_asyncio/test_events.py4
3 files changed, 5 insertions, 10 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index d082bcc..5694f29 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -18,7 +18,6 @@ import collections
import concurrent.futures
import heapq
import logging
-import math
import socket
import subprocess
import time
@@ -97,7 +96,7 @@ class BaseEventLoop(events.AbstractEventLoop):
self._default_executor = None
self._internal_fds = 0
self._running = False
- self.granularity = time.get_clock_info('monotonic').resolution
+ self._granularity = time.get_clock_info('monotonic').resolution
def _make_socket_transport(self, sock, protocol, waiter=None, *,
extra=None, server=None):
@@ -605,8 +604,6 @@ 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
@@ -632,9 +629,7 @@ class BaseEventLoop(events.AbstractEventLoop):
self._process_events(event_list)
# Handle 'later' callbacks that are ready.
- now = self.time()
- # round current time aways from zero
- now = math.ceil(now / self.granularity) * self.granularity
+ now = self.time() + 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 900eec0..94408f8 100644
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -36,7 +36,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._granularity = max(selector.resolution, self._granularity)
self._make_self_pipe()
def _make_socket_transport(self, sock, protocol, waiter=None, *,
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index bded1a3..fe5b224 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -1170,9 +1170,9 @@ class EventLoopTestsMixin:
def wait():
loop = self.loop
calls.append(loop._run_once_counter)
- yield from asyncio.sleep(loop.granularity * 10, loop=loop)
+ yield from asyncio.sleep(loop._granularity * 10, loop=loop)
calls.append(loop._run_once_counter)
- yield from asyncio.sleep(loop.granularity / 10, loop=loop)
+ yield from asyncio.sleep(loop._granularity / 10, loop=loop)
calls.append(loop._run_once_counter)
self.loop.run_until_complete(wait())