[issue20320] select.select(timeout) and select.kqueue.control(timeout) must round the timeout to the upper bound

STINNER Victor report at bugs.python.org
Tue Jan 21 01:34:16 CET 2014


New submission from STINNER Victor:

Rounding issue causes performance bug in asyncio, see issue #20311 for the rationale. This issue address bugs for select and kqueue because their implementation is different.

OS multiplexer:

- select: microsecond resolution (10^-6), timeout converted by _PyTime_ObjectToTimeval() which converts 1e-7 to zero => BUG!
- 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()

Attached patch adds a new round parameter to _PyTime_ObjectToTimeval() and _PyTime_ObjectToTimespec() to choose the rounding method:

* _PyTime_ROUND_DOWN: Round towards zero. (current implementation)
* _PyTime_ROUND_UP: Round away from zero. (new rounding method)

The patch changes the rounding method for select, kqueue but also for sigtimedwait().

----------
files: time_rouding.patch
keywords: patch
messages: 208594
nosy: belopolsky, haypo, neologix, pitrou, serhiy.storchaka, skrah
priority: normal
severity: normal
status: open
title: select.select(timeout) and select.kqueue.control(timeout) must round the timeout to the upper bound
versions: Python 3.3, Python 3.4
Added file: http://bugs.python.org/file33581/time_rouding.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20320>
_______________________________________


More information about the Python-bugs-list mailing list