diff -r 8962d1c442a6 Python/traceback.c --- a/Python/traceback.c Mon Oct 28 08:08:09 2013 +0100 +++ b/Python/traceback.c Mon Oct 28 17:47:38 2013 +0100 @@ -240,9 +240,21 @@ int if (filename == NULL) return 0; - io = PyImport_ImportModuleNoBlock("io"); - if (io == NULL) - return -1; + if (_Py_Finalizing) { + PyInterpreterState *interp = PyThreadState_GET()->interp; + io = PyDict_GetItemString(interp->modules, "io"); + if (io == NULL) { + /* Don't reload the io module during Python finalization */ + return 0; + } + Py_INCREF(io); + } + else { + io = PyImport_ImportModuleNoBlock("io"); + if (io == NULL) + return -1; + } + binary = _PyObject_CallMethodId(io, &PyId_open, "Os", filename, "rb"); if (binary == NULL) {