Skip to content

Commit 72d7028

Browse files
committed
avoid keeping a ref to result for test_thread_pool.ThreadPoolExecutorTest.test_free_reference
1 parent b864ef9 commit 72d7028

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Lib/concurrent/futures/_base.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ def map(self, fn, *iterables, timeout=None, chunksize=1, buffersize=None):
621621
# collected independently of the result_iterator closure.
622622
executor_weakref = weakref.ref(self)
623623

624+
result = collections.deque(maxlen=1)
624625
# Yield must be hidden in closure so that the futures are submitted
625626
# before the first iterator value is required.
626627
def result_iterator():
@@ -630,16 +631,18 @@ def result_iterator():
630631
while fs:
631632
# Careful not to keep a reference to the popped future
632633
if timeout is None:
633-
result = _result_or_cancel(fs.pop())
634+
result.append(_result_or_cancel(fs.pop()))
634635
else:
635-
result = _result_or_cancel(fs.pop(), end_time - time.monotonic())
636+
result.append(
637+
_result_or_cancel(fs.pop(), end_time - time.monotonic())
638+
)
636639
if (
637640
buffersize
638641
and (executor := executor_weakref())
639642
and (args := next(zipped_iterables, None))
640643
):
641644
fs.appendleft(executor.submit(fn, *args))
642-
yield result
645+
yield result.pop()
643646
finally:
644647
for future in fs:
645648
future.cancel()

0 commit comments

Comments
 (0)