[New-bugs-announce] [issue20311] epoll.poll(timeout) must round the timeout to the upper bound
STINNER Victor
report at bugs.python.org
Mon Jan 20 11:33:28 CET 2014
New submission from STINNER Victor:
Hi, while comparing performances of Tulip and Trollius projects (asyncio module), I found a bug. The event loop is called too many times when a callback is scheduled with a timeout and the epoll selector is used, especially for timeout close to one millisecond.
In my opinion, it's a bug in epoll.poll(): it should wait *at least* timeout seconds if no event is received, not shorter.
Pseudo-code of Tulip:
---
timeout = scheduled[0].when - time.monotonic()
events = selector.select(timeout)
process_events(events)
while scheduled:
if scheduled[0].when > time.monotonic():
break
...
---
The problem is that "scheduled[0].when > time.monotonic()" test fails because epoll.poll() returns in less than timeout seconds.
The difference between the timeout and elapsed time is very small, less than 1 millisecond.
Attached patch fixes this issue by rounding the timeout to the upper bound.
The rounding is different than datetime.timedelta constructor for example, because the usecase is different. epoll.poll(0.0001) calls epoll_wait() with a timemout of 1 millisecond (1e-4 rounded to 1e-3).
epoll.poll(0.0) still calls epoll_wait() with a timeout of 0 millisecond. I don't think that it's possible to write a reliable unit test for that on our slow buildbots.
----------
files: epoll_timeout.patch
keywords: patch
messages: 208532
nosy: gvanrossum, haypo, neologix, pitrou, serhiy.storchaka
priority: normal
severity: normal
status: open
title: epoll.poll(timeout) must round the timeout to the upper bound
versions: Python 3.3, Python 3.4
Added file: http://bugs.python.org/file33563/epoll_timeout.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20311>
_______________________________________
More information about the New-bugs-announce
mailing list