You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Free-threaded failure in gaussian_process/tests/test_gpc.py::test_multi_class_n_jobs[kernel3] with dictionary changed size during iteration #33152
@propertydefhyperparameters(self):
"""Returns a list of all hyperparameter specifications."""r= [
getattr(self, attr)
>forattrindir(self)
^^^^^^^^^ifattr.startswith("hyperparameter_")
]
ERuntimeError: dictionarychangedsizeduringiterationself=1.25**2
../sklearn/gaussian_process/kernels.py:280: RuntimeErrorPARALLELFAILEDgaussian_process/tests/test_gpc.py::test_multi_class_n_jobs[kernel3] -RuntimeError: dictionarychangedsizeduringiteration
Note: this is a specific race condition discovered on the free-threading build that leverages pytest-run-parallel to detect concurrency problems. I labeled this issue as free threading, but it might be possible to trigger it on a regular Python build with pytest-run-parallel (I haven't tried).
Side-comment the name of the issue is not very descriptive it should mention the name of the job e.g. Linux x86-64 pylatest_free_threaded in this case. I think otherwise all failures will be grouped in the same tracking issue, cc @FrancoisPgm.
Does someone know why the dictionary would change? It looks like it should contain the attributes of a class, surely that is a static thing? It makes me think of #33067 - isn't the list of hyperparamters something that is known? Could we compute it once when the class is instantiated? Maybe this would help avoid the problem that is causing this.
Does someone know why the dictionary would change?
Not sure. What happens with pytest-run-parallel is that the same test function is run in multiple separate threads. With parametrized tests, the kernel instances are shared between the two threads see Quansight-Labs/pytest-run-parallel#14 for more details.
So maybe fitting in one thread modifies the kernel instance while the other thread is iterating over dir(self) (self is a kernel instance). Another potential "fix" would be to do kernel = clone(kernel) in the test maybe?
changed the title [-]⚠️ CI failed on Unit tests (last failure: Jan 29, 2026) ⚠️[/-][+]Free-threaded failure with dictionary changed size during iteration in gaussian_process/tests/test_gpc.py::test_multi_class_n_jobs[kernel3][/+]on Feb 6, 2026
changed the title [-]Free-threaded failure with dictionary changed size during iteration in gaussian_process/tests/test_gpc.py::test_multi_class_n_jobs[kernel3][/-][+]Free-threaded failure in `gaussian_process/tests/test_gpc.py::test_multi_class_n_jobs[kernel3]` with `dictionary changed size during iteration`[/+]on Feb 6, 2026
So maybe fitting in one thread modifies the kernel instance while the other thread is iterating over dir(self) (self is a kernel instance). Another potential "fix" would be to do kernel = clone(kernel) in the test maybe?
It's true that all parametrized tests with mutable input value such as kernels or estimators should always clone/copy those values to avoid cross-tests side effects.
Activity
StefanieSenger commentedon Jan 29, 2026
Jan 29:
RuntimeErrorin Linux x86-64 pylatest_free_threaded:Full stack-trace
scikit-learn-bot commentedon Jan 30, 2026
CI is no longer failing! ✅
Successful run on Feb 05, 2026
ogrisel commentedon Jan 30, 2026
Note: this is a specific race condition discovered on the free-threading build that leverages
pytest-run-parallelto detect concurrency problems. I labeled this issue as free threading, but it might be possible to trigger it on a regular Python build withpytest-run-parallel(I haven't tried).lesteve commentedon Feb 2, 2026
Side-comment the name of the issue is not very descriptive it should mention the name of the job e.g.
Linux x86-64 pylatest_free_threadedin this case. I think otherwise all failures will be grouped in the same tracking issue, cc @FrancoisPgm.lesteve commentedon Feb 2, 2026
FYI I haven't managed to reproduce locally the issue from #33152 (comment). The following command doesn't fail for me:
The last free-threaded "dictionary changed size during iteration" issue I could remember #32264.
ogrisel commentedon Feb 3, 2026
Note that it should be easy to fix with a
.copy()(I think):... for attr in dir(self).copy() ...but it's unfortunate that we cannot easily reproduce to check that this candidate fix actually works.
betatim commentedon Feb 5, 2026
Does someone know why the dictionary would change? It looks like it should contain the attributes of a class, surely that is a static thing? It makes me think of #33067 - isn't the list of hyperparamters something that is known? Could we compute it once when the class is instantiated? Maybe this would help avoid the problem that is causing this.
lesteve commentedon Feb 5, 2026
Not sure. What happens with pytest-run-parallel is that the same test function is run in multiple separate threads. With parametrized tests, the kernel instances are shared between the two threads see Quansight-Labs/pytest-run-parallel#14 for more details.
So maybe fitting in one thread modifies the kernel instance while the other thread is iterating over
dir(self)(selfis a kernel instance). Another potential "fix" would be to dokernel = clone(kernel)in the test maybe?[-]⚠️ CI failed on Unit tests (last failure: Jan 29, 2026) ⚠️[/-][+]Free-threaded failure with dictionary changed size during iteration in gaussian_process/tests/test_gpc.py::test_multi_class_n_jobs[kernel3][/+][-]Free-threaded failure with dictionary changed size during iteration in gaussian_process/tests/test_gpc.py::test_multi_class_n_jobs[kernel3][/-][+]Free-threaded failure in `gaussian_process/tests/test_gpc.py::test_multi_class_n_jobs[kernel3]` with `dictionary changed size during iteration`[/+]lesteve commentedon Feb 6, 2026
Let's see how often this happens in the new automated and updated free-threaded issue #33216.
I rename the issue title to make it more explicit that this is about this specific failure.
ogrisel commentedon Feb 6, 2026
It's true that all parametrized tests with mutable input value such as kernels or estimators should always clone/copy those values to avoid cross-tests side effects.
lesteve commentedon Oct 14, 2026
We haven't seen this in the CI again that I could easily find at least. I wasn't able to reproduce locally. Let's close this one.