diff -r 92039fb68483 Python/pythonrun.c --- a/Python/pythonrun.c Thu Aug 15 11:57:19 2013 +0200 +++ b/Python/pythonrun.c Thu Aug 15 12:17:28 2013 +0200 @@ -503,6 +503,10 @@ Py_Finalize(void) wait_for_thread_shutdown(); + /* Clear profiling and tracing functions */ + PyEval_SetTrace(NULL, NULL); + PyEval_SetProfile(NULL, NULL); + /* The interpreter is still entirely intact at this point, and the * exit funcs may be relying on that. In particular, if some thread * or exit func is still waiting to do an import, the import machinery