Skip to content

MAINT: avoid possible race condition by not touching os.environ on import.#30657

Merged
charris merged 1 commit intonumpy:maintenance/2.4.xfrom
charris:backport-30637
Jan 15, 2026
Merged

MAINT: avoid possible race condition by not touching os.environ on import.#30657
charris merged 1 commit intonumpy:maintenance/2.4.xfrom
charris:backport-30637

Conversation

@charris
Copy link
Copy Markdown
Member

@charris charris commented Jan 15, 2026

Backport of #30637.

We need to set the OPENBLAS_MAIN_FREE environment variable before the OpenBLAS initialization runs, however we don't need to touch os.environ for that. Deleting a key from os.environ can lead to a race condition when numpy is imported in parallel in multiple threads, while os.unsetenv always succeeds. See gh-30627 for context.

Also clean up GOTOBLAS_MAIN_FREE, that's a deprecated env var that has the same function as OPENBLAS_MAIN_FREE. There won't be any GotoBLAS or early OpenBLAS versions in use anymore that only have the GOTOBLAS flavor.

Closes gh-30627
Closes gh-21223

…import

We need to set the `OPENBLAS_MAIN_FREE` environment variable before the OpenBLAS
initialization runs, however we don't need to touch `os.environ` for that.
Deleting a key from `os.environ` can lead to a race condition when numpy is
imported in parallel in multiple threads, while `os.unsetenv` always succeeds.
See numpygh-30627 for context.

Also clean up `GOTOBLAS_MAIN_FREE`, that's a deprecated env var that has the
same function as `OPENBLAS_MAIN_FREE`. There won't be any GotoBLAS or early
OpenBLAS versions in use anymore that only have the GOTOBLAS flavor.

Closes numpygh-30627
Closes numpygh-21223
@charris charris added this to the 2.4.2 release milestone Jan 15, 2026
@charris charris merged commit 2e501ca into numpy:maintenance/2.4.x Jan 15, 2026
74 checks passed
@charris charris deleted the backport-30637 branch January 15, 2026 23:37
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.

2 participants