Skip to content

Commit ec3741e

Browse files
pablogsaltiran
andcommitted
Update Modules/atexitmodule.c
Co-authored-by: Christian Heimes <[email protected]>
1 parent ebc949b commit ec3741e

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Lib/test/_test_atexit.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ def func():
123123
1/0
124124
atexit.register(func)
125125
try:
126-
atexit._run_exitfuncs()
126+
with support.catch_unraisable_exception() as cm:
127+
atexit._run_exitfuncs()
128+
self.assertEqual(cm.unraisable.object, func)
129+
self.assertEqual(cm.unraisable.exc_type, ZeroDivisionError)
130+
self.assertEqual(type(cm.unraisable.exc_value), ZeroDivisionError)
127131
finally:
128132
atexit.unregister(func)
129133

Modules/atexitmodule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ atexit_callfuncs(struct atexit_state *state)
9494
}
9595

9696
// bpo-46025: Increment the refcount of cb->func as the call itself may unregister it
97-
PyObject* the_func = cb->func;
98-
Py_INCREF(the_func);
97+
PyObject* the_func = Py_NewRef(cb->func);
9998
PyObject *res = PyObject_Call(cb->func, cb->args, cb->kwargs);
10099
if (res == NULL) {
101100
_PyErr_WriteUnraisableMsg("in atexit callback", the_func);

0 commit comments

Comments
 (0)