Closed
Description
Bug report
Bug description:
Sequence iterators are not thread-safe under the free-threaded build. They'll sometimes be accessed with the same index.
Here is a minimal repro:
import concurrent.futures
N = 10000
for _ in range(100):
it = iter(range(N))
with concurrent.futures.ThreadPoolExecutor() as executor:
data = set(executor.map(lambda _: next(it), range(N)))
assert len(data) == N, f"Expected {N} distinct elements, got {len(data)}"
I also tested it with list
and dict
iterators as well as a custom class implementing __getitem__
.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux, macOS