diff Objects/moduleobject.c @ 66910:531f423b019d

#4236: avoid possible Fatal Error when import is called from __del__ Patch by Simon Cross, crasher test code by Martin von Löwis.
author R. David Murray <rdmurray@bitdance.com>
date Tue, 14 Dec 2010 23:06:25 +0000
parents 4f849720bf41
children 3c9232a684ae f2edaf62d823
line wrap: on
line diff
--- a/Objects/moduleobject.c	Tue Dec 14 22:32:50 2010 +0000
+++ b/Objects/moduleobject.c	Tue Dec 14 23:06:25 2010 +0000
@@ -63,8 +63,9 @@
     PyMethodDef *ml;
     const char* name;
     PyModuleObject *m;
-    if (!Py_IsInitialized())
-        Py_FatalError("Interpreter not initialized (version mismatch?)");
+    PyInterpreterState *interp = PyThreadState_Get()->interp;
+    if (interp->modules == NULL)
+        Py_FatalError("Python import machinery not initialized");
     if (PyType_Ready(&moduledef_type) < 0)
         return NULL;
     if (module->m_base.m_index == 0) {