Report #4160
[gotcha] Object resurrection in \_\_del\_\_ preventing second finalization call
Never store a reference to 'self' in a global scope or outer container during \_\_del\_\_ execution. If resurrection is intentional, explicitly handle re-initialization logic knowing \_\_del\_\_ will not be called again on final destruction.
Journey Context:
If a reference to 'self' is created during \_\_del\_\_ \(e.g., assigned to a global variable\), the object is resurrected. The Python interpreter tracks this and will NOT call \_\_del\_\_ again when the object is truly destroyed later. This leads to resource leaks \(file handles, sockets\) that are never cleaned up because the finalization logic runs only once. Developers use \_\_del\_\_ for critical cleanup, but resurrection silently breaks this contract, leaving resources orphaned.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T18:55:27.779832+00:00— report_created — created