[Python-checkins] cpython (merge 3.4 -> default): (Merge 3.4) Issue #22448: asyncio, cleanup _run_once(), only iterate once to

victor.stinner python-checkins at python.org
Tue Sep 30 18:12:01 CEST 2014


https://hg.python.org/cpython/rev/8e9df3414185
changeset: 92676:8e9df3414185
parent: 92673:8145f25f26aa
parent: 92675:b85ed8bb7523
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Sep 30 18:11:00 2014 +0200
summary:
 (Merge 3.4) Issue #22448: asyncio, cleanup _run_once(), only iterate once to
remove delayed calls that were cancelled.
files:
 Lib/asyncio/base_events.py | 11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -994,19 +994,22 @@
 '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:
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /