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

Skip to content

TST Fix test_frozen.py not thread safe - #34449

Merged
ogrisel merged 3 commits into
scikit-learn:mainfrom
jeremiedbb:fix-frozen-tests-not-thread-safe
Jul 10, 2026
Merged

TST Fix test_frozen.py not thread safe#34449
ogrisel merged 3 commits into
scikit-learn:mainfrom
jeremiedbb:fix-frozen-tests-not-thread-safe

Conversation

@jeremiedbb

Copy link
Copy Markdown
Member

Found by the lock file bump for free-threaded: https://github.com/scikit-learn/scikit-learn/actions/runs/28772508237/job/85309154191?pr=34406

request.getfixturevalue is not thread safe.

Anyway, the fixtures in this file are probably not used as expected. By default they are function scoped so the wrapped function (make_regression, make_classification) is called for every test and every parametrization. It means that there's also a possible race condition when a fixture is used in 2 tests when the 2 tests are called at the same time and the fixture is being setup concurrently by 2 threads.

Since the fixtures are just one liners that wrap a function call that is very fast and doesn't use a lot of memory, I think we can simply remove the fixtures and call the dataset generators directly. This is guaranteed to be thread safe.

Another option could be to scope the fixture for the session and make sure they are setup in an eager way (autouse=True does that I believe), but it doesn't seem necessary here and I'd rather go for the more simple way.

@jeremiedbb jeremiedbb added Build / CI Quick Review For PRs that are quick to review free-threading PRs and issues related to support for free-threaded CPython (a.k.a. nogil or no-GIL, PEP 703) labels Jul 8, 2026

@thomasjpfan thomasjpfan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ogrisel
ogrisel enabled auto-merge (squash) July 10, 2026 15:47
@ogrisel
ogrisel merged commit 6b9e392 into scikit-learn:main Jul 10, 2026
36 checks passed
prady0t pushed a commit to prady0t/scikit-learn that referenced this pull request Sep 2, 2026
@jeremiedbb
jeremiedbb deleted the fix-frozen-tests-not-thread-safe branch September 3, 2026 15:25
@jeremiedbb jeremiedbb mentioned this pull request Sep 8, 2026
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Build / CI free-threading PRs and issues related to support for free-threaded CPython (a.k.a. nogil or no-GIL, PEP 703) No Changelog Needed Quick Review For PRs that are quick to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants