Skip to content

gh-123471: Make concurrent iteration over itertools.accumulate thread-safe#144486

Open
eendebakpt wants to merge 4 commits intopython:mainfrom
eendebakpt:accumulate_ft_v2
Open

gh-123471: Make concurrent iteration over itertools.accumulate thread-safe#144486
eendebakpt wants to merge 4 commits intopython:mainfrom
eendebakpt:accumulate_ft_v2

Conversation

@eendebakpt
Copy link
Contributor

@eendebakpt eendebakpt commented Feb 4, 2026

We use a critical section similar to the approach in #132814.

Note: the accumulate has mutable internal state lz->initial and lz->total. With some refactoring we can replace the lz->init pointer with a C int (where atomics can be used), but the lz->total remains a pointer that is mutated on each iteration.

A side benefit of the refactoring would be that a decref in accumulate_dealloc is avoided and visit in accumulate_traverse. I decided not to include the refactoring in this PR (it would involve some churn), but if a core dev feels otherwise I will include it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant