Skip to content

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

Merged
mattip merged 1 commit intonumpy:mainfrom
rgommers:fix-openblas-environ-race
Jan 11, 2026
Merged

MAINT: avoid possible race condition by not touching os.environ on import#30637
mattip merged 1 commit intonumpy:mainfrom
rgommers:fix-openblas-environ-race

Conversation

@rgommers
Copy link
Copy Markdown
Member

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 (may lead to a KeyError), 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
@mattip mattip merged commit 89776e2 into numpy:main Jan 11, 2026
76 checks passed
@mattip
Copy link
Copy Markdown
Member

mattip commented Jan 11, 2026

Thanks @rgommers

@rgommers rgommers deleted the fix-openblas-environ-race branch January 11, 2026 19:58
@charris charris added the 09 - Backport-Candidate PRs tagged should be backported label Jan 11, 2026
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

3 participants