]> granicus.if.org Git - python/commitdiff
Merge latest Tulip into asyncio
authorVictor Stinner <victor.stinner@gmail.com>
Sat, 25 Jan 2014 23:02:31 +0000 (00:02 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Sat, 25 Jan 2014 23:02:31 +0000 (00:02 +0100)
- Make the new granularity attribute private
- Simplify BaseEventLoop._run_once(): avoid math.ceil(), use simple arithmetic
  instead

Doc/library/asyncio-eventloop.rst
Lib/asyncio/base_events.py
Lib/asyncio/selector_events.py
Lib/test/test_asyncio/test_events.py

index 4d26f4e50ff1d13e6f736e759262ec42399cdcb9..953fa49386cd0833e1b03709950858122f7d2a74 100644 (file)
@@ -144,12 +144,6 @@ a different clock than :func:`time.time`.
    Return the current time, as a :class:`float` value, according to the
    event loop's internal clock.
 
-.. attribute:: BaseEventLoop.granularity
-
-   Granularity of the time: maximum between the resolution of the
-   :meth:`BaseEventLoop.time` method and the resolution of the selector (see
-   :attr:`selectors.BaseSelector.resolution`).
-
 .. seealso::
 
    The :func:`asyncio.sleep` function.
index d082bccf2733c3eae54d09498790747ecaea40d6..5694f296fb6873353fe79cfd1094e3d5616a39c2 100644 (file)
@@ -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:
index 900eec01333f765434e9fa5718fae7d1695df42c..94408f82b493fdf919b3b6f1cfeabc57670f8dc8 100644 (file)
@@ -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, *,
index bded1a3bf1e3337c69f764fe0918b0a95e198ee1..fe5b2246ee19cb434fe4bca97e92c650d7b2ffde 100644 (file)
@@ -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())