cpython: 90354a4c9dde (original) (raw)
Mercurial > cpython
changeset 88694:90354a4c9dde
Issue #20311: Revert e042ea77a152 and 7ce7295393c2, PollSelector.select() and EpollSelector.select() round again the timeout towards zero [#20311]
Victor Stinner victor.stinner@gmail.com | |
---|---|
date | Sat, 25 Jan 2014 14:43:45 +0100 |
parents | caab3e191485 |
children | 3b8a2281d323 |
files | Lib/selectors.py Lib/test/test_selectors.py Misc/NEWS |
diffstat | 3 files changed, 2 insertions(+), 32 deletions(-)[+] [-] Lib/selectors.py 10 Lib/test/test_selectors.py 19 Misc/NEWS 5 |
line wrap: on
line diff
--- a/Lib/selectors.py +++ b/Lib/selectors.py @@ -8,7 +8,6 @@ This module allows high-level and effici 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[](#l1.15)
# zero to wait *at least* timeout seconds.[](#l1.16)
timeout = int(math.ceil(timeout * 1e3))[](#l1.17)
# Round towards zero[](#l1.18)
timeout = int(timeout * 1000)[](#l1.19) ready = [][](#l1.20) try:[](#l1.21) fd_event_list = self._poll.poll(timeout)[](#l1.22)
@@ -415,10 +413,6 @@ if hasattr(select, 'epoll'): timeout = -1 elif timeout <= 0: timeout = 0
else:[](#l1.27)
# epoll_wait() has a resolution of 1 millisecond, round away[](#l1.28)
# from zero to wait *at least* timeout seconds.[](#l1.29)
timeout = math.ceil(timeout * 1e3) * 1e-3[](#l1.30) max_ev = len(self._fd_to_key)[](#l1.31) ready = [][](#l1.32) try:[](#l1.33)
--- a/Lib/test/test_selectors.py +++ b/Lib/test/test_selectors.py @@ -363,25 +363,6 @@ class BaseSelectorTestCase(unittest.Test 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[](#l2.8)
# least* timeout seconds. For example, epoll_wait() has a resolution of[](#l2.9)
# 1 ms (10^-3), epoll.select(0.0001) must wait 1 ms, not 0 ms.[](#l2.10)
s = self.SELECTOR()[](#l2.11)
self.addCleanup(s.close)[](#l2.12)
rd, wr = self.make_socketpair()[](#l2.14)
s.register(rd, selectors.EVENT_READ)[](#l2.15)
for timeout in (1e-2, 1e-3, 1e-4):[](#l2.17)
t0 = perf_counter()[](#l2.18)
s.select(timeout)[](#l2.19)
dt = perf_counter() - t0[](#l2.20)
clock = get_clock_info('perf_counter')[](#l2.21)
self.assertGreaterEqual(dt, timeout,[](#l2.22)
"%.30f < %.30f ; clock=%s"[](#l2.23)
% (dt, timeout, clock))[](#l2.24)
- class ScalableSelectorMixIn:
--- 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