M
Maxim Khitrov
Greetings,
The threading module uses time.time in _Condition and _Thread classes
to implement timeouts. On Windows, time() typically has a resolution
of 15.625ms. In addition, if the system clock is changed (though ntp,
for example) it would reflect that change, causing the timeout to last
longer or shorter depending on which way the update went.
Would it not be better to use time.clock() instead? The resolution is
much better, and the value is not linked to system clock. Right now, I
replace the threading._time reference with clock in some of my
programs and everything works perfectly. Condition and Event timeouts
are precise down to the millisecond (resolution of the sleep
function), and I see no side-effects.
Is it possible to make that change part of the module itself (keeping
time() for linux systems), or can someone think of a reason why using
clock is a bad idea? I know that it's using QueryPerformanceCounter
for implementation, which has some known issues, but I still think
that the advantages outweigh potential faults.
- Max
The threading module uses time.time in _Condition and _Thread classes
to implement timeouts. On Windows, time() typically has a resolution
of 15.625ms. In addition, if the system clock is changed (though ntp,
for example) it would reflect that change, causing the timeout to last
longer or shorter depending on which way the update went.
Would it not be better to use time.clock() instead? The resolution is
much better, and the value is not linked to system clock. Right now, I
replace the threading._time reference with clock in some of my
programs and everything works perfectly. Condition and Event timeouts
are precise down to the millisecond (resolution of the sleep
function), and I see no side-effects.
Is it possible to make that change part of the module itself (keeping
time() for linux systems), or can someone think of a reason why using
clock is a bad idea? I know that it's using QueryPerformanceCounter
for implementation, which has some known issues, but I still think
that the advantages outweigh potential faults.
- Max