2014/1/24 Ben Darnell <[email protected]>: > On Fri, Jan 24, 2014 at 10:48 AM, Victor Stinner <[email protected]> > wrote: >> But it looks like all these rounding functions are not enough: >> http://bugs.python.org/issue20311#msg208927 >> >> I proposed a different patch reverting my changes in select and >> selectors module and use instead a new granularity to round timings >> only in asyncio, in BaseEventLoop._run_once(). The granularity uses >> not only the resolution of the selector, but also the resolution of >> the clock. It has at least an impact on Windows (clock resolution: >> 15.6 ms) and FreeBSD (kqueue resolution: 1e-9, clock: 11-e9). > > I think using max(requested_timeout, resolution) is a better solution than > using math.ceil, but I'm surprised that the system clock resolution matters > as well (the underlying system call should be taking care of this).
The clock resolution matters, so the BaseEventLoop._run_once() method to understand why. Basically, in the problematic case, selector.select() works like a sleep, and _run_once() checks if the deadline of the next scheduled handle was reached. Depending how the sleep duration was computed, the deadline may not been reached yet. Example: - clock resolution: 1 ms - selector resolution: 1 us - next callback: 35.1 us The selector will be used to sleep 36 us. Time delta: 0 ms, because 36 us is smaller than the clock resolution (1 ms). Victor
