Closed
Description
The docs at https://python.readthedocs.io/en/stable/extending/newtypes.html#finalization-and-de-allocation note that dealloc funcs need to be careful to work correctly in the presence of a pending exception, because deallocation may happen in unwinding while an exception is pending.
func_dealloc
, code_dealloc
, and dict_dealloc
all may call watcher callbacks with a deallocation event. We shouldn't call a user callback with a pending exception set; this could cause all kinds of hard-to-debug issues. We should save/restore the exception around the callback.