From 9a2488d64d6e84285cc090207e72be01ed059a9d Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Wed, 26 Feb 2025 08:59:19 -0700 Subject: [PATCH] Don't use gc.get_objects on the free-threaded build --- tests/test_gc.rs | 5 +++++ 1 file changed, 5 insertions(+) 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()