Kaydet (Commit) 68da8fc4 authored tarafından Victor Stinner's avatar Victor Stinner

Issue #22448: asyncio, cleanup _run_once(), only iterate once to remove delayed

calls that were cancelled.
üst 5083828d
...@@ -994,19 +994,22 @@ class BaseEventLoop(events.AbstractEventLoop): ...@@ -994,19 +994,22 @@ class BaseEventLoop(events.AbstractEventLoop):
'call_later' callbacks. 'call_later' callbacks.
""" """
# Remove delayed calls that were cancelled if their number is too high
sched_count = len(self._scheduled) sched_count = len(self._scheduled)
if (sched_count > _MIN_SCHEDULED_TIMER_HANDLES and if (sched_count > _MIN_SCHEDULED_TIMER_HANDLES and
self._timer_cancelled_count / sched_count > self._timer_cancelled_count / sched_count >
_MIN_CANCELLED_TIMER_HANDLES_FRACTION): _MIN_CANCELLED_TIMER_HANDLES_FRACTION):
# Remove delayed calls that were cancelled if their number
# is too high
new_scheduled = []
for handle in self._scheduled: for handle in self._scheduled:
if handle._cancelled: if handle._cancelled:
handle._scheduled = False handle._scheduled = False
else:
new_scheduled.append(handle)
self._scheduled = [x for x in self._scheduled if not x._cancelled] heapq.heapify(new_scheduled)
self._scheduled = new_scheduled
self._timer_cancelled_count = 0 self._timer_cancelled_count = 0
heapq.heapify(self._scheduled)
else: else:
# Remove delayed calls that were cancelled from head of queue. # Remove delayed calls that were cancelled from head of queue.
while self._scheduled and self._scheduled[0]._cancelled: while self._scheduled and self._scheduled[0]._cancelled:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment