MCPcopy Index your code
hub / github.com/RustPython/RustPython / try_call_finalizer

Method try_call_finalizer

crates/vm/src/object/core.rs:1696–1713  ·  view source on GitHub ↗

Call __del__ if present, without triggering object deallocation. Used by GC to call finalizers before breaking cycles. This allows proper resurrection detection. PyObject_CallFinalizerFromDealloc

(&self)

Source from the content-addressed store, hash-verified

1694 /// This allows proper resurrection detection.
1695 /// PyObject_CallFinalizerFromDealloc
1696 pub fn try_call_finalizer(&self) {
1697 let del = self.class().slots.del.load();
1698 if let Some(slot_del) = del
1699 && !self.gc_finalized()
1700 {
1701 // Mark as finalized BEFORE calling __del__ to prevent double-call
1702 // This ensures drop_slow_inner() won't call __del__ again
1703 self.set_gc_finalized();
1704 let result = crate::vm::thread::with_vm(self, |vm| {
1705 if let Err(e) = slot_del(self, vm)
1706 && let Some(del_method) = self.get_class_attr(identifier!(vm, __del__))
1707 {
1708 vm.run_unraisable(e, None, del_method);
1709 }
1710 });
1711 let _ = result;
1712 }
1713 }
1714
1715 /// Clear weakrefs but collect callbacks instead of calling them.
1716 /// This is used by GC to ensure ALL weakrefs are cleared BEFORE any callbacks run.

Callers 1

collect_innerMethod · 0.80

Calls 7

with_vmFunction · 0.85
gc_finalizedMethod · 0.80
set_gc_finalizedMethod · 0.80
get_class_attrMethod · 0.80
run_unraisableMethod · 0.80
loadMethod · 0.45
classMethod · 0.45

Tested by

no test coverage detected