]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-145703: Fix `asyncio.BaseEventLoop` low clock resolution (#145706)
authorKonstantin Vlasov <CaptainFlint@users.noreply.github.com>
Sat, 14 Mar 2026 05:37:30 +0000 (06:37 +0100)
committerGitHub <noreply@github.com>
Sat, 14 Mar 2026 05:37:30 +0000 (11:07 +0530)
Lib/asyncio/base_events.py
Misc/NEWS.d/next/Library/2026-03-09-19-59-05.gh-issue-145703.4EEP7J.rst [new file with mode: 0644]

index b565b1d8a9e2263d1f5469a0d0ea62dca78b165a..0930ef403c6c4be495224b10e052be94dc482885 100644 (file)
@@ -19,14 +19,15 @@ import concurrent.futures
 import errno
 import heapq
 import itertools
+import math
 import os
 import socket
 import stat
 import subprocess
+import sys
 import threading
 import time
 import traceback
-import sys
 import warnings
 import weakref
 
@@ -2022,7 +2023,10 @@ class BaseEventLoop(events.AbstractEventLoop):
         event_list = None
 
         # Handle 'later' callbacks that are ready.
-        end_time = self.time() + self._clock_resolution
+        now = self.time()
+        # Ensure that `end_time` is strictly increasing
+        # when the clock resolution is too small.
+        end_time = now + max(self._clock_resolution, math.ulp(now))
         while self._scheduled:
             handle = self._scheduled[0]
             if handle._when >= end_time:
diff --git a/Misc/NEWS.d/next/Library/2026-03-09-19-59-05.gh-issue-145703.4EEP7J.rst b/Misc/NEWS.d/next/Library/2026-03-09-19-59-05.gh-issue-145703.4EEP7J.rst
new file mode 100644 (file)
index 0000000..bc239ce
--- /dev/null
@@ -0,0 +1,3 @@
+:mod:`asyncio`: Make sure that :meth:`loop.call_at <asyncio.loop.call_at>` and
+:meth:`loop.call_later <asyncio.loop.call_later>` trigger scheduled events on
+time when the clock resolution becomes too small.