Skip to content

Conversation

charris
Copy link
Member

@charris charris commented Feb 23, 2025

Backport #28361.

We add a test for np.nonzero under multi-threading and make np.nonzero safe under the cpython free-threading build. We want to ensure concurrent invocations of the method on the same array do not corrupt the system. Correct results are not guaranteed:

  • If the underlying data is changing, the non-zero indices are not well-defined
  • If the underlying data is changing, we can get indices outside the size of the array due to a part of the return array not being initialized.

Also see #27519. An alternative approach would be to use locks to make the array read-only during the operation.

@charris charris added 00 - Bug 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 Feb 23, 2025
@charris charris added this to the 2.2.4 release milestone Feb 23, 2025
@charris charris merged commit fc594d4 into numpy:maintenance/2.2.x Feb 23, 2025
67 of 70 checks passed
@charris charris deleted the backport-28361 branch February 23, 2025 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug 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.

3 participants