Message 208540 - Python tracker (original) (raw)
select.select(), selectors.PollSelector.select(), select.epoll.poll(), select.kqueue.control() have the bug.
OS multiplexers:
- select: microsecond resolution (10^-6), timeout converted by _PyTime_ObjectToTimeval() which converts 1e-7 to zero => BUG!
- poll: millisecond resolution (10^-3) but expects int type, select is ok, selectors uses int(1000 * timeout) which converts 1e-4 to zero => BUG!
- epoll: millisecond resolution (10^-3), select uses (int)(dtimeout * 1000.0) which converts 1e-4 to zero => BUG!
- devpoll: millisecond resolution (10^-3) but expects int type, select is ok, selectors doesn't support it yet => ok
- kqueue: nanosecond resolution (10^-9), timeout converted by _PyTime_ObjectToTimespec() which converts 1e-10 to zero => BUG!
_PyTime_ObjectToTimeval() is used in various places:
- datetime.datetime.fromtimestamp(), datetime.datetime.utcfromtimestamp()
- select.select(),
_PyTime_ObjectToTimespec() is used in various places:
- posix.utime()
- signal.sigtimedwait()
- select.kqueue.control()
- time.clock_settime()
A new parameter should be added to _PyTime_ObjectToTimeval() and _PyTime_ObjectToTimespec() to choose the rounding method.
--
I saw the bug with poll and epoll because these functions have the worst resolution (millisecond). Attached patch fixes poll and epoll, and add a generic test on all selectors: select_round_timeout.patch.
According to my test, select.select() has an effective resolution of 0.1 ms (10^4) on my Fedora 19 (Linux kernel 3.12), so I don't think that the select rounding issue is important. Tell me if you consider that _PyTime_ObjectToTime*() (select, kqueue) should be fixed. If yes, I will open a separated issue (because the implementation is different and it may impact other unrelated functions).