]> granicus.if.org Git - python/commitdiff
Issue #20311: Revert e042ea77a152 and 7ce7295393c2, PollSelector.select() and
authorVictor Stinner <victor.stinner@gmail.com>
Sat, 25 Jan 2014 13:43:45 +0000 (14:43 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Sat, 25 Jan 2014 13:43:45 +0000 (14:43 +0100)
EpollSelector.select() round again the timeout towards zero

Lib/selectors.py
Lib/test/test_selectors.py
Misc/NEWS

index 1bdf972cdf7387021a2b559362003cdf54157f7e..cd8b29e4cc2c246a63e901f51cf566172efb1574 100644 (file)
@@ -8,7 +8,6 @@ This module allows high-level and efficient I/O multiplexing, built upon the
 from abc import ABCMeta, abstractmethod
 from collections import namedtuple, Mapping
 import functools
-import math
 import select
 import sys
 
@@ -357,9 +356,8 @@ if hasattr(select, 'poll'):
             elif timeout <= 0:
                 timeout = 0
             else:
-                # poll() has a resolution of 1 millisecond, round away from
-                # zero to wait *at least* timeout seconds.
-                timeout = int(math.ceil(timeout * 1e3))
+                # Round towards zero
+                timeout = int(timeout * 1000)
             ready = []
             try:
                 fd_event_list = self._poll.poll(timeout)
@@ -415,10 +413,6 @@ if hasattr(select, 'epoll'):
                 timeout = -1
             elif timeout <= 0:
                 timeout = 0
-            else:
-                # epoll_wait() has a resolution of 1 millisecond, round away
-                # from zero to wait *at least* timeout seconds.
-                timeout = math.ceil(timeout * 1e3) * 1e-3
             max_ev = len(self._fd_to_key)
             ready = []
             try:
index 130e0a8c1f5e15a2b48934eece612a89a2505b5d..529290460f4dea1bbc1c90f5ce3299400cda7ae9 100644 (file)
@@ -363,25 +363,6 @@ class BaseSelectorTestCase(unittest.TestCase):
         self.assertFalse(s.select(2))
         self.assertLess(time() - t, 2.5)
 
-    def test_timeout_rounding(self):
-        # Issue #20311: Timeout must be rounded away from zero to wait *at
-        # least* timeout seconds. For example, epoll_wait() has a resolution of
-        # 1 ms (10^-3), epoll.select(0.0001) must wait 1 ms, not 0 ms.
-        s = self.SELECTOR()
-        self.addCleanup(s.close)
-
-        rd, wr = self.make_socketpair()
-        s.register(rd, selectors.EVENT_READ)
-
-        for timeout in (1e-2, 1e-3, 1e-4):
-            t0 = perf_counter()
-            s.select(timeout)
-            dt = perf_counter() - t0
-            clock = get_clock_info('perf_counter')
-            self.assertGreaterEqual(dt, timeout,
-                                    "%.30f < %.30f ; clock=%s"
-                                    % (dt, timeout, clock))
-
 
 class ScalableSelectorMixIn:
 
index 9fa175033df10ea5872fe9d44caf1d381d44c49d..c298260c5bb82a0f93f42175b0867467c9bd1b99 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -40,11 +40,6 @@ Library
   which it could get an inspect.Signature is a callable written in Python.
   Fix courtesy of Michael Foord.
 
-- Issue #20311: selector.PollSelector.select() now rounds the timeout away from
-  zero, instead of rounding towards zero. For example, a timeout of one
-  microsecond is now rounded to one millisecond, instead of being rounded to
-  zero.
-
 - Issue #20317: ExitStack.__exit__ could create a self-referential loop if an
   exception raised by a cleanup operation already had its context set
   correctly (for example, by the @contextmanager decorator). The infinite