From 567b26e882a3a73f37f69390f3a34ec533ff4590 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 21 Jan 2014 21:00:47 +0100 Subject: [PATCH] Issue #20311: EpollSelector now also rounds the timeout towards zero, as PollSelector. This change is not really required in Python 3.4, since select.epoll.poll() now rounds also correctly the timeout. But Guido van Rossum prefers to have exactly the same selectors.py file in CPython and Tulip projects: "it's not harmful". --- Lib/selectors.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Lib/selectors.py b/Lib/selectors.py index f8b56cd4331..1bdf972cdf7 100644 --- a/Lib/selectors.py +++ b/Lib/selectors.py @@ -411,7 +411,14 @@ def unregister(self, fileobj): return key def select(self, timeout=None): - timeout = -1 if timeout is None else max(timeout, 0) + if timeout is None: + 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: