bpo-27144: concurrent.futures as_complete and map iterators do not keep reference to returned object by grzgrzgrz3 · Pull Request #1560 · python/cpython (original) (raw)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do not remove waiter, second result set on future will trigger waiter and cause KeyError, future is already returned and reference cleared.
For example:
>>> from concurrent.futures import Future, as_completed
>>> fs_finished = Future()
>>> fs = Future()
>>> fs_finished.set_result("")
>>> for x in as_completed([fs_finished, fs, Future()]):
... fs.set_result(None)
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/grzegorz/cpython/Lib/concurrent/futures/_base.py", line 235, in as_completed
pending.remove(future)
KeyError: <Future at 0x7f566ff6fc20 state=finished returned NoneType>
This error occurs in both version.
However docstring for Future.set_result
and Future.set_exception
says:
Should only be used by Executor implementations and unit tests.
So maybe we should ignore this case?