Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.2k
Description
Bug report
Bug description:
There have been a few discussions over this bit of code fromLib/asyncio/base_events.py:
end_time=self.time()+self._clock_resolutionwhileself._scheduled:handle=self._scheduled[0]ifhandle._when>=end_time:breakhandle=heapq.heappop(self._scheduled)handle._scheduled=Falseself._ready.append(handle)
It has implicit dependency on the current system uptime. The clock resolution in my test environment was equal to 1e-09, and as soon astime.monotonic() (which is uptime on Linux systems) reaches 16M seconds (just over 194 days), the floating point precision shifts, and the addition of 1e-09 does not change the time value anymore. Which causes the comparison to become invalid, and the scheduled events not trigger at their exact designated time.
What if instead of adding the same fixed resolution value, we use an adaptive value that increases to match the current floating point precision?
I've looked through the discussions that seemed relevant, but didn't find any similar suggestions (although I could have missed them).
I'll create a pull request shortly to illustrate my idea.
Some of the relevant discussions:
#64704 (looks like the original addition of the current code)
#116342 (a very close hit; it looks to me, like the situation was misjudged a little in that dialog)
#110695 (not directly related to this issue, but also deals with clock resolution under specific scenario)
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status