Skip to main content

clone_py_object

Function clone_py_object 

Source
pub fn clone_py_object(obj: &Py<PyAny>) -> Py<PyAny>
Expand description

Clones a Python object reference by attaching to the interpreter.

The result is a second strong reference to the same object, so this does not break a reference cycle. When a Rust object holds a Py<T> whose Python object reaches back into Rust, cloning adds another strong edge to that cycle rather than removing one.

Break such a back-reference with a Python weak reference (see upgrade_py_weakref) or an explicit terminal release point that drops the strong reference during disposal.