diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-01-31 13:06:25 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-01-31 13:06:25 +0100 |
commit | 49556edac764ec6fd3619abe7ab8991ec9855cc5 (patch) | |
tree | 3967c2c520c86b24c2902a3d49e3e01f4080a21b /asyncio/selectors.py | |
parent | 300da1630e4ee1338fb3e9d81be2be4d09133652 (diff) | |
download | trollius-49556edac764ec6fd3619abe7ab8991ec9855cc5.tar.gz |
selectors: round (again) timeout away from zero for poll and epoll
Diffstat (limited to 'asyncio/selectors.py')
-rw-r--r-- | asyncio/selectors.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/asyncio/selectors.py b/asyncio/selectors.py index b1b530a..52ee8db 100644 --- a/asyncio/selectors.py +++ b/asyncio/selectors.py @@ -8,6 +8,7 @@ This module allows high-level and efficient I/O multiplexing, built upon the from abc import ABCMeta, abstractmethod, abstractproperty from collections import namedtuple, Mapping import functools +import math import select import sys @@ -369,8 +370,9 @@ if hasattr(select, 'poll'): elif timeout <= 0: timeout = 0 else: - # Round towards zero - timeout = int(timeout * 1000) + # poll() has a resolution of 1 millisecond, round away from + # zero to wait *at least* timeout seconds. + timeout = int(math.ceil(timeout * 1e3)) ready = [] try: fd_event_list = self._poll.poll(timeout) @@ -430,6 +432,10 @@ 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: |