Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make functools.lru_cache thread-safe in --disable-gil builds #112070

Closed
Tracked by #108219
colesbury opened this issue Nov 14, 2023 · 1 comment · Fixed by #112111
Closed
Tracked by #108219

Make functools.lru_cache thread-safe in --disable-gil builds #112070

colesbury opened this issue Nov 14, 2023 · 1 comment · Fixed by #112111
Assignees
Labels
3.13 bugs and security fixes extension-modules C modules in the Modules dir topic-free-threading type-feature A feature request or enhancement

Comments

@colesbury
Copy link
Contributor

colesbury commented Nov 14, 2023

Feature or enhancement

We should make functools.lru_cache thread-safe in the --disable-gil builds.

For context, here is the commit from the nogil-3.12 fork: colesbury/nogil-3.12@041a08e339

NOTES (differences in 3.13 from nogil-3.12):

  1. No need for an extra mutex in lru_cache_object; every PyObject has a mutex in the --disable-gil builds
  2. For _functools__lru_cache_wrapper_cache_info_impl and _functools__lru_cache_wrapper_cache_clear_impl we should instead use the @critical_section Arugment Clinic directive. This will be simpler and require fewer changes to the code. lru_cache_call still needs explicit calls to the critical section API.

Linked PRs

@colesbury colesbury added type-feature A feature request or enhancement 3.13 bugs and security fixes topic-free-threading labels Nov 14, 2023
@AlexWaygood AlexWaygood added the extension-modules C modules in the Modules dir label Nov 14, 2023
@wanderxjtu
Copy link
Contributor

I will try on it.

wanderxjtu added a commit to wanderxjtu/cpython that referenced this issue Nov 15, 2023
wanderxjtu added a commit to wanderxjtu/cpython that referenced this issue Nov 15, 2023
wanderxjtu added a commit to wanderxjtu/cpython that referenced this issue Nov 15, 2023
wanderxjtu added a commit to wanderxjtu/cpython that referenced this issue Nov 15, 2023
wanderxjtu added a commit to wanderxjtu/cpython that referenced this issue Nov 15, 2023
wanderxjtu added a commit to wanderxjtu/cpython that referenced this issue Nov 15, 2023
wanderxjtu added a commit to wanderxjtu/cpython that referenced this issue Nov 16, 2023
corona10 pushed a commit that referenced this issue Nov 17, 2023
…ld (gh-112111)

* gh-112070: make `functools.lrucacle` threadsafe in --disable-gil build

* gh-112070: update generate `functoolsmodule` files

* gh-112070: add NEWS file

* Delete Misc/NEWS.d/next/Library/2023-11-15-20-19-45.gh-issue-112070.q6OhcU.rst

* gh-112070: reformat functoolsmodule.c

---------

Co-authored-by: Sam Gross <colesbury@gmail.com>
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
…il build (pythongh-112111)

* pythongh-112070: make `functools.lrucacle` threadsafe in --disable-gil build

* pythongh-112070: update generate `functoolsmodule` files

* pythongh-112070: add NEWS file

* Delete Misc/NEWS.d/next/Library/2023-11-15-20-19-45.gh-issue-112070.q6OhcU.rst

* pythongh-112070: reformat functoolsmodule.c

---------

Co-authored-by: Sam Gross <colesbury@gmail.com>
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
…il build (pythongh-112111)

* pythongh-112070: make `functools.lrucacle` threadsafe in --disable-gil build

* pythongh-112070: update generate `functoolsmodule` files

* pythongh-112070: add NEWS file

* Delete Misc/NEWS.d/next/Library/2023-11-15-20-19-45.gh-issue-112070.q6OhcU.rst

* pythongh-112070: reformat functoolsmodule.c

---------

Co-authored-by: Sam Gross <colesbury@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes extension-modules C modules in the Modules dir topic-free-threading type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants