https://github.com/python/cpython/commit/97ff57fba3544034b64a513306295174a317e6c7
commit: 97ff57fba3544034b64a513306295174a317e6c7
branch: main
author: Andrew Svetlov <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2026-11-03T11:51:40+05:30
summary:

gh-161032: Convert BaseEventLoop._clock_resolution to 
asyncio.constants.CLOCK_RESOLUTION (#161033)

files:
M Lib/asyncio/base_events.py
M Lib/asyncio/constants.py
M Lib/test/test_asyncio/test_events.py
M Lib/test/test_asyncio/utils.py

diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 9eb34c5f29fb55..861210775347ae 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -432,7 +432,6 @@ def __init__(self):
         # Identifier of the thread running the event loop, or None if the
         # event loop is not running
         self._thread_id = None
-        self._clock_resolution = time.get_clock_info('monotonic').resolution
         self._exception_handler = None
         self.set_debug(coroutines._is_debug_mode())
         # The preserved state of async generator hooks.
@@ -2057,7 +2056,7 @@ def _run_once(self):
         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))
+        end_time = now + max(constants.CLOCK_RESOLUTION, math.ulp(now))
         while self._scheduled:
             handle = self._scheduled[0]
             if handle._when >= end_time:
diff --git a/Lib/asyncio/constants.py b/Lib/asyncio/constants.py
index b60c1e4236af1f..e0788851e187e7 100644
--- a/Lib/asyncio/constants.py
+++ b/Lib/asyncio/constants.py
@@ -3,6 +3,7 @@
 # SPDX-FileCopyrightText: Copyright (c) 2015-2021 MagicStack Inc.  
http://magic.io
 
 import enum
+import time
 
 # After the connection is lost, log warnings after this many write()s.
 LOG_THRESHOLD_FOR_CONNLOST_WRITES = 5
@@ -33,6 +34,9 @@
 # Default timeout for joining the threads in the threadpool
 THREAD_JOIN_TIMEOUT = 300
 
+# Resolution of the clock used by the event loop, in seconds.
+CLOCK_RESOLUTION = time.get_clock_info('monotonic').resolution
+
 # The enum should be here to break circular dependencies between
 # base_events and sslproto
 class _SendfileMode(enum.Enum):
diff --git a/Lib/test/test_asyncio/test_events.py 
b/Lib/test/test_asyncio/test_events.py
index 58556cc87409f7..33444c76290b6b 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -27,6 +27,7 @@
     import tty
 
 import asyncio
+from asyncio import constants
 from asyncio import coroutines
 from asyncio import events
 from asyncio import selector_events
@@ -2314,7 +2315,7 @@ async def wait():
         # of the clock used by the kernel. Tolerate a few useless calls on
         # these platforms.
         self.assertLessEqual(self.loop._run_once_counter, 20,
-            {'clock_resolution': self.loop._clock_resolution,
+            {'clock_resolution': constants.CLOCK_RESOLUTION,
              'selector': self.loop._selector.__class__.__name__})
 
     def test_remove_fds_after_closing(self):
diff --git a/Lib/test/test_asyncio/utils.py b/Lib/test/test_asyncio/utils.py
index e86c221d7f7025..86a2e812b6619e 100644
--- a/Lib/test/test_asyncio/utils.py
+++ b/Lib/test/test_asyncio/utils.py
@@ -360,7 +360,6 @@ def gen():
         self._gen = gen()
         next(self._gen)
         self._time = 0
-        self._clock_resolution = 1e-9
         self._timers = []
         self._selector = TestSelector()
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to