Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH: fix thread-unsafe C API usages #27166

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

Merged
merged 1 commit into from
Aug 10, 2024

Conversation

charris
Copy link
Member

@charris charris commented Aug 9, 2024

Backport of #27145.

Ref #26159

See also the CPython HOWTO on this topic: https://docs.python.org/3.13/howto/free-threading-extensions.html#freethreading-extensions-howto.

The remaining usages of PyDict_GetItem and PyDict_Next are all around the fields attribute of structured dtypes. I'm pretty sure that dictionary is effectively frozen after the DType is constructed, so I don't worry about those uses.

It's not straightforward to write tests for this, I'm just applying static refactorings in places where the refactoring shouldn't introduce new reference counting bugs.

  • ENH: fix thread-unsafe C API usages

  • ENH: use critical sections in einsum

  • BUG: fix error handling in loadtxt C code

  • revert einsum changes

Ref numpy#26159

See also the CPython HOWTO on this topic: https://docs.python.org/3.13/howto/free-threading-extensions.html#freethreading-extensions-howto.

The remaining usages of PyDict_GetItem and PyDict_Next are all around the fields attribute of structured dtypes. I'm pretty sure that dictionary is effectively frozen after the DType is constructed, so I don't worry about those uses.

It's not straightforward to write tests for this, I'm just applying static refactorings in places where the refactoring shouldn't introduce new reference counting bugs.

* ENH: fix thread-unsafe C API usages

* ENH: use critical sections in einsum

* BUG: fix error handling in loadtxt C code

* revert einsum changes
@charris charris added 01 - Enhancement 08 - Backport Used to tag backport PRs 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703) labels Aug 9, 2024
@charris charris added this to the 2.1.0 release milestone Aug 9, 2024
@charris charris merged commit 4fa80b8 into numpy:maintenance/2.1.x Aug 10, 2024
65 checks passed
@charris charris deleted the backport-27145 branch August 10, 2024 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
01 - Enhancement 08 - Backport Used to tag backport PRs 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants