Skip to content

Commit f509097

Browse files
committed
lighter ref cycle break
1 parent 0d70be9 commit f509097

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Lib/concurrent/futures/_base.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -633,11 +633,14 @@ def result_iterator():
633633

634634
# yield the awaited result
635635
yield fs.pop()._result
636+
except:
637+
# break the reference cycle with fs[-1]._exception's traceback
638+
fs.pop().cancel()
639+
raise
636640
finally:
637-
while fs:
638-
# cancel pending futures, popping them to break potential
639-
# reference cycles with future._exception.__traceback__
640-
fs.pop().cancel()
641+
for future in fs:
642+
future.cancel()
643+
641644
return result_iterator()
642645

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

0 commit comments

Comments
 (0)