diff --git a/tests/test_gc.rs b/tests/test_gc.rs index eb2cb34e1d7..a88b9a21f91 100644 --- a/tests/test_gc.rs +++ b/tests/test_gc.rs @@ -4,6 +4,7 @@ use pyo3::class::PyTraverseError; use pyo3::class::PyVisit; use pyo3::ffi; use pyo3::prelude::*; +#[cfg(not(Py_GIL_DISABLED))] use pyo3::py_run; #[cfg(not(target_arch = "wasm32"))] use std::cell::Cell; @@ -182,6 +183,10 @@ fn test_cycle_clear() { inst.borrow_mut().cycle = Some(inst.clone().into_any().unbind()); + // gc.get_objects can create references to partially initialized objects, + // leading to races on the free-threaded build. + // see https://github.com/python/cpython/issues/130421#issuecomment-2682924142 + #[cfg(not(Py_GIL_DISABLED))] py_run!(py, inst, "import gc; assert inst in gc.get_objects()"); check.assert_not_dropped(); inst.as_ptr()