Skip to content
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

Don't use gc.get_objects on the free-threaded build #4938

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/test_gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
Loading