Skip to content

CI Run free-threaded test suite with pytest-run-parallel - #32023

Merged
ogrisel merged 57 commits into
scikit-learn:mainfrom
lesteve:free-threaded-pytest-run-parallel
Sep 2, 2025
Merged

ogrisel merged 57 commits into
scikit-learn:mainfrom
lesteve:free-threaded-pytest-run-parallel

Conversation

@lesteve

@lesteve lesteve commented Aug 27, 2025 •

Copy link
Copy Markdown
Member

Part of #30007

  • going for Python 3.14 seems like the best bet. I get segmentation faults from time to time on Python 3.13 when running locally. They seem related to warnings looking at the Python traceback.

Edit: scipy free-threaded Python 3.14 package was added in conda-forge so the following 2 points are not a problem anymore:

@github-actions

github-actions Bot commented Aug 27, 2025 •

Copy link
Copy Markdown

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 177ac96. Link to the linter CI: here

@lesteve
lesteve force-pushed the free-threaded-pytest-run-parallel branch from 5e0ee8f to 47b7d33 Compare August 27, 2025 10:43
# reset stop word validation
del vec._stop_words_id
assert _check_stop_words_consistency(vec) is False
with pytest.warns(UserWarning, match=message):

@lesteve lesteve Sep 1, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the actual fix, see previous discussion in #32023 (comment).

My guess right now is that the first call _check_stop_words_consistency was raising a warning and that the next pytest.warns was sometimes failing because of the default warnings once strategy plus some unfavourable thread ordering. By putting this inside pytest.warns we avoid the side-effect and the second warning is always issued.

warnings.simplefilter("error", UserWarning)
vec.fit_transform(["hello world"])
assert _check_stop_words_consistency(vec) is None
# Only one warning per stop list

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was an oversight. This puts this block inside the for loop. Previously, this block was not inside the for loop so only the last element of the loop was tested ...

# if the parameter is deprecated, don't show it
continue
finally:
warnings.filters.pop(0)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I rewrote this test a bit to rely on warnings.catch_warnings to reset the warnings filters.

With Python 3.14 free-threading, warning.simplefilter does not modify warnings.filters any more inside a warnings.catch_warnings context, see https://docs.python.org/3.14/whatsnew/3.14.html#concurrent-safe-warnings-control.

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

Since the remaining test_filter_warning_propagates failure is caused by a bug in joblib/loky, I would just mark it as thread unsafe with an XXX comment linking to the upstream issue.

Comment thread sklearn/utils/parallel.py Resolved
Comment thread sklearn/utils/tests/test_parallel.py Resolved
@lesteve
lesteve marked this pull request as ready for review September 2, 2025 05:16
@lesteve

lesteve commented Sep 2, 2025 •

Copy link
Copy Markdown
Member Author

codecov being red is likely because there is no coverage in the free-threaded CI build. I guess we could look at this in a further PR but I don't think this is very high priority:
image

@ogrisel
ogrisel merged commit ed0a98a into scikit-learn:main Sep 2, 2025
@ogrisel

ogrisel commented Sep 2, 2025

Copy link
Copy Markdown
Member

Thanks @lesteve!

@lesteve
lesteve deleted the free-threaded-pytest-run-parallel branch September 2, 2025 11:11
DeaMariaLeon pushed a commit to DeaMariaLeon/scikit-learn that referenced this pull request Sep 12, 2025
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