Skip to content

Commit ed1654f

Browse files
committed
Issue #20505: BaseEventLoop uses again the resolution of the clock to decide if
scheduled tasks should be executed or not.
1 parent b38b5c4 commit ed1654f

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

Lib/asyncio/base_events.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def __init__(self):
9696
self._default_executor = None
9797
self._internal_fds = 0
9898
self._running = False
99+
self._clock_resolution = time.get_clock_info('monotonic').resolution
99100

100101
def _make_socket_transport(self, sock, protocol, waiter=None, *,
101102
extra=None, server=None):
@@ -643,10 +644,10 @@ def _run_once(self):
643644
self._process_events(event_list)
644645

645646
# Handle 'later' callbacks that are ready.
646-
now = self.time()
647+
end_time = self.time() + self._clock_resolution
647648
while self._scheduled:
648649
handle = self._scheduled[0]
649-
if handle._when > now:
650+
if handle._when >= end_time:
650651
break
651652
handle = heapq.heappop(self._scheduled)
652653
self._ready.append(handle)

Lib/test/test_asyncio/test_events.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,15 +1178,15 @@ def wait():
11781178
yield from asyncio.sleep(1e-4, loop=loop)
11791179
yield from asyncio.sleep(1e-6, loop=loop)
11801180
yield from asyncio.sleep(1e-8, loop=loop)
1181+
yield from asyncio.sleep(1e-10, loop=loop)
11811182

11821183
self.loop.run_until_complete(wait())
1183-
# The ideal number of call is 10, but on some platforms, the selector
1184+
# The ideal number of call is 12, but on some platforms, the selector
11841185
# may sleep at little bit less than timeout depending on the resolution
1185-
# of the clock used by the kernel. Tolerate 5 useless calls on these
1186-
# platforms.
1187-
self.assertLessEqual(self.loop._run_once_counter, 15,
1188-
{'time_info': time.get_clock_info('time'),
1189-
'monotonic_info': time.get_clock_info('monotonic'),
1186+
# of the clock used by the kernel. Tolerate a few useless calls on
1187+
# these platforms.
1188+
self.assertLessEqual(self.loop._run_once_counter, 20,
1189+
{'clock_resolution': self.loop._clock_resolution,
11901190
'selector': self.loop._selector.__class__.__name__})
11911191

11921192

0 commit comments

Comments
 (0)