Skip to content

Commit 77c06f3

Browse files
authored
gh-145703: Fix asyncio.BaseEventLoop low clock resolution (#145706)
1 parent 3c38feb commit 77c06f3

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Lib/asyncio/base_events.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
import errno
2020
import heapq
2121
import itertools
22+
import math
2223
import os
2324
import socket
2425
import stat
2526
import subprocess
27+
import sys
2628
import threading
2729
import time
2830
import traceback
29-
import sys
3031
import warnings
3132
import weakref
3233

@@ -2022,7 +2023,10 @@ def _run_once(self):
20222023
event_list = None
20232024

20242025
# Handle 'later' callbacks that are ready.
2025-
end_time = self.time() + self._clock_resolution
2026+
now = self.time()
2027+
# Ensure that `end_time` is strictly increasing
2028+
# when the clock resolution is too small.
2029+
end_time = now + max(self._clock_resolution, math.ulp(now))
20262030
while self._scheduled:
20272031
handle = self._scheduled[0]
20282032
if handle._when >= end_time:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:mod:`asyncio`: Make sure that :meth:`loop.call_at <asyncio.loop.call_at>` and
2+
:meth:`loop.call_later <asyncio.loop.call_later>` trigger scheduled events on
3+
time when the clock resolution becomes too small.

0 commit comments

Comments
 (0)