STINNER Victor added the comment:

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).

----------
title: epoll.poll(timeout) must round the timeout to the upper bound -> 
epoll.poll(timeout) and PollSelector.select(timeout) must round the timeout to 
the upper bound
Added file: http://bugs.python.org/file33564/select_round_timeout.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue20311>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to