Index: Python/pythonrun.c =================================================================== --- Python/pythonrun.c (revision 73857) +++ Python/pythonrun.c (working copy) @@ -1685,8 +1685,33 @@ if (exitfunc) { PyObject *res; + int should_warn = 1; + Py_INCREF(exitfunc); PySys_SetObject("exitfunc", (PyObject *)NULL); + if (PyFunction_Check(exitfunc)) { + PyObject *atexit_str; + PyFunctionObject *f = (PyFunctionObject *)exitfunc; + + atexit_str = PyString_FromString("atexit"); + if (atexit_str) { + /* Don't warn when the exit function come from + the atexit module, or when there was an + error. */ + should_warn = !PyObject_RichCompareBool( + atexit_str, f->func_module, Py_EQ); + Py_DECREF(atexit_str); + } + else { + PyErr_Clear(); + should_warn = 0; + } + } + if (should_warn) { + PyErr_WarnPy3k("sys.exitfunc is not supported in 3.x; " + "use the atexit module instead.", 1); + PyErr_Clear(); + } res = PyEval_CallObject(exitfunc, (PyObject *)NULL); if (res == NULL) { if (!PyErr_ExceptionMatches(PyExc_SystemExit)) {