From: Konstantin Vlasov Date: Sat, 14 Mar 2026 05:37:30 +0000 (+0100) Subject: gh-145703: Fix `asyncio.BaseEventLoop` low clock resolution (#145706) X-Git-Tag: v3.15.0a8~319 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77c06f3da629b5088975309959ef6895bef841e3;p=thirdparty%2FPython%2Fcpython.git gh-145703: Fix `asyncio.BaseEventLoop` low clock resolution (#145706) --- diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index b565b1d8a9e2..0930ef403c6c 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -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 index 000000000000..bc239ce58c9e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-03-09-19-59-05.gh-issue-145703.4EEP7J.rst @@ -0,0 +1,3 @@ +:mod:`asyncio`: Make sure that :meth:`loop.call_at ` and +:meth:`loop.call_later ` trigger scheduled events on +time when the clock resolution becomes too small.