Skip to content

Commit 0d70be9

Browse files
committed
break other potential reference cycles with fs, not only the one caused by fs[-1]
1 parent 3be6956 commit 0d70be9

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

Lib/concurrent/futures/_base.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,11 +634,10 @@ def result_iterator():
634634
# yield the awaited result
635635
yield fs.pop()._result
636636
finally:
637-
if fs:
638-
# break a reference cycle with fs[-1]._exception
637+
while fs:
638+
# cancel pending futures, popping them to break potential
639+
# reference cycles with future._exception.__traceback__
639640
fs.pop().cancel()
640-
for future in fs:
641-
future.cancel()
642641
return result_iterator()
643642

644643
def shutdown(self, wait=True, *, cancel_futures=False):

0 commit comments

Comments
 (0)