[issue34535] queue.Queue(timeout=0.001) avg delay Windows:14.5ms, Ubuntu: 0.063ms

Eryk Sun report at bugs.python.org
Wed Mar 17 13:33:36 EDT 2021


Eryk Sun <eryksun at gmail.com> added the comment:

See the related discussion in bpo-41299. The system interrupt period can be lowered to 1 ms with timeBeginPeriod() -- or lower with undocumented NtSetTimerResolution(). This affects the resolution of dispatcher waits such as Sleep() and WaitForSingleObject(), as well as the resolution of Query[Unbiased]InterruptTime(). But apparently GetTickCount[64]() has a fixed update frequency of 64 ticks/second (15.625 ms period), regardless of the system interrupt period. The combination of WaitForSingleObject() with GetTickCount64() has marginally better resolution and consistent performance if the system interrupt period is lowered to 1 ms.

If a wait needs to be resumable in order to handle SIGINT, and it should perform consistently with other waits, then there are two choices. One option is to base the timeout on Query[Unbiased]InterruptTime(), for which the resolution depends on the system interrupt period. Conversely, if we want all waits to perform consistently and independent of the system interrupt period, then they should all depend on GetTickCount64(). This could be implemented in one place, such as Modules/signalmodule.c, with the addition of _Py_Sleep(), Py_WaitForSingleObject(), and _Py_WaitForMultipleObjects(). On the main thread, these wait functions would include the SIGINT event and resume the wait if the SIGINT handler doesn't raise an exception.

----------
versions: +Python 3.10, Python 3.8, Python 3.9 -Python 3.6, Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34535>
_______________________________________


More information about the Python-bugs-list mailing list