-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Closed
Closed
Copy link
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
Here’s the corrected version with Markdown syntax escaped where necessary:
import random
from concurrent.futures import ThreadPoolExecutor
random.seed(42)
data = [[random.random() for _ in range(1024)] for _ in range(16)]
with ThreadPoolExecutor(1) as pool:
futures = [pool.submit(lambda: sum(x)) for x in data]
results = [f.result() for f in futures]
print(results)
Output on CPython 3.13:
[523.3398190464421, 509.139502449254, 509.139502449254, 509.139502449254, 509.139502449254, 509.139502449254, 509.139502449254, 509.139502449254, 509.139502449254, 509.139502449254, 509.139502449254, 509.139502449254, 509.139502449254, 509.139502449254, 509.139502449254, 509.139502449254]
If I run it differently — for example, with [pool.submit(sum, x) for x in data]
or [pool.submit(partial(sum, x)) for x in data]
— everything works as expected: I’m getting different results.
I can also reproduce it with a simpler version, using no sum or any other function, although it gives fewer duplicates, so the results are less stable:
import random
from concurrent.futures import ThreadPoolExecutor
random.seed(42)
data = [[random.random()] for _ in range(16)]
with ThreadPoolExecutor(1) as pool:
futures = [pool.submit(lambda: x) for x in data]
results = [f.result() for f in futures]
print(results)
I tested and reproduced the issue on the latest CPython releases from 3.9 to 3.13, and 3.14a4 on x86_64 Linux.
Additionally, I tested it on:
- aarch64 Linux CPython 3.13
- aarch64 macOS CPython 3.13
- x86_64 Linux PyPy 3.11
CPython versions tested on:
3.9, 3.10, 3.11, 3.12, 3.13, 3.14
Operating systems tested on:
Linux, macOS
Metadata
Metadata
Assignees
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error