Skip to content

ENH: fix thread-unsafe C API usages - #27166

Merged
charris merged 1 commit into
numpy:maintenance/2.1.xfrom
charris:backport-27145
Aug 10, 2024
Merged

charris merged 1 commit into
numpy:maintenance/2.1.xfrom
charris:backport-27145

Conversation

@charris

@charris charris commented Aug 9, 2024

Copy link
Copy Markdown
Member

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
@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