]> granicus.if.org Git - python/commitdiff
Issue #20311: EpollSelector now also rounds the timeout towards zero, as
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 21 Jan 2014 20:00:47 +0000 (21:00 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 21 Jan 2014 20:00:47 +0000 (21:00 +0100)
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

index f8b56cd4331c61ef84f1af46b504731238be8dab..1bdf972cdf7387021a2b559362003cdf54157f7e 100644 (file)
@@ -411,7 +411,14 @@ if hasattr(select, 'epoll'):
             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: