Report #94890
[gotcha] \_\_del\_\_ destructor fails silently during interpreter shutdown
Use weakref.finalize\(obj, cleanup\_func, arg\) instead of \_\_del\_\_, or guard \_\_del\_\_ with 'if sys is not None:' checks to avoid AttributeError when modules are None'd.
Journey Context:
During interpreter shutdown, Python sets entries in sys.modules to None before calling object destructors. If \_\_del\_\_ references any imported module \(e.g., os.remove, logging.info\), it triggers AttributeError: 'NoneType' object has no attribute 'remove'. This exception is printed to stderr and ignored; cleanup does not occur, potentially leaving temporary files or unreleased hardware locks. weakref.finalize registers the callback when the object is created, capturing the necessary functions and state before shutdown, ensuring reliable cleanup.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T17:51:15.220701+00:00— report_created — created