summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-09-30 16:08:36 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-09-30 16:08:36 (GMT)
commit68da8fc4c0b4b2f640bd09b7b0e3214b263fac0d (patch)
tree0bb9c0e012aebf7a00374fbb065c04153a5824a1 /Lib/asyncio
parent5083828d65b6eb617d4333a1c0c4c9b7c3f452a6 (diff)
downloadcpython-68da8fc4c0b4b2f640bd09b7b0e3214b263fac0d.zip
cpython-68da8fc4c0b4b2f640bd09b7b0e3214b263fac0d.tar.gz
cpython-68da8fc4c0b4b2f640bd09b7b0e3214b263fac0d.tar.bz2
Issue #22448: asyncio, cleanup _run_once(), only iterate once to remove delayed
calls that were cancelled.
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/base_events.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 5aaf58f..3cff72a 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -994,19 +994,22 @@ class BaseEventLoop(events.AbstractEventLoop):
'call_later' callbacks.
"""
- # Remove delayed calls that were cancelled if their number is too high
sched_count = len(self._scheduled)
if (sched_count > _MIN_SCHEDULED_TIMER_HANDLES and
self._timer_cancelled_count / sched_count >
_MIN_CANCELLED_TIMER_HANDLES_FRACTION):
+ # Remove delayed calls that were cancelled if their number
+ # is too high
+ new_scheduled = []
for handle in self._scheduled:
if handle._cancelled:
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
-
- heapq.heapify(self._scheduled)
else:
# Remove delayed calls that were cancelled from head of queue.
while self._scheduled and self._scheduled[0]._cancelled: