-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
DEBUG Thread parallel tests #30041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
DEBUG Thread parallel tests #30041
Conversation
Note that, I don't plan to continue manually flagging test functions individually. It's too tedious and invasive. |
I updated the PR to simplify it and rely on automated thread-unsafety heuristics of the latest version of I started to run Note that tests collection itself is slow, but still bearable compared to the actual test execution time and the memory usage problem. I guess we will need to profile a run on submodule of scikit-learn to check whether the slowdown is expected: when running with For the record, I created the nogil env using conda-forge:
|
To avoid the memory usage problem, I reduced the parallelism to 2 threads and run 1 iteration of the tests per thread:
Here are the result: pytest_all.log There are 146 errors. Many of those are caused by the use of stateful generators in |
This is an investigative branch, not meant to be merged as such, to investigate what effort would be required to tackle #30007 as a whole (using
pytest-run-parallel
instead ofpytest-freethreaded
).It includes commits from:
That can be merged independently.
On top of this, I started to use
@pytest.mark.parallel_threads(1)
(EDIT: now@pytest.mark.thread_unsafe
) on tests that are fundamentally not thread-safe or that use other fixtures such astmpdir
that would require to be initialized in the thread running the test to function properly (as opposed to running in the mainpytest
thread).Many more similar changes to silence all the non-informative failures, but I will stop there for now.
This already highlights that the most common patterns are:
pytest.warns
;sys.stdout
withcapsys
;tmpdir
fixture;monkeypatch
fixture.EDIT: since the first version of this PR,
pytest-run-parallel
has been updated to make thetmpdir
andtmp_path
fixture work by default and automatically detect tests that use problematic fixtures and code patterns involving warnings automatically. The remaining problematic fixtures can probably be added by configuration.I have also found a failure in
test_minibatch_kmeans_partial_fit_init
with the lambda init case using:and I cannot explain it yet (using regular Python with GIL enabled).