Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Lib/asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions Lib/asyncio/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_asyncio/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_asyncio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Loading