Python crash

Adrian Leu AdrianLeu at kelseus.com
Tue Feb 19 16:54:29 CET 2002


Hi !
I have written a script which I am calling from inside a C++
application using:

 module = PyImport_ImportModule( ... ) and 
 method = PyObject_CallMethod( ... ) 

methods. 

This script is called for a certain amount of times (depending on the
user). Initially I call Py_Initialize() and the last command
Py_Finalize() is called at the end (when the user does not want to
call the script anymore). It looks like it is working OK until after a
few repeats the system crashed with the following stack view (showing
that the error/crash is in the PyImport_ImportModule function and it
is related to the deallocation of the module pointer - I also get the
"Fatal Python error: UNREF invalid object" error in the output
window):

NTDLL! 77f9eea9()
_Py_ForgetReference(_object * 0x02da59dc) line 956 + 10 bytes
_Py_Dealloc(_object * 0x02da59dc) line 977 + 9 bytes
class_dealloc(PyClassObject * 0x02da42ec) line 114 + 62 bytes
_Py_Dealloc(_object * 0x02da42ec) line 978 + 7 bytes
tupledealloc(PyTupleObject * 0x02da7e3c) line 151 + 93 bytes
_Py_Dealloc(_object * 0x02da7e3c) line 978 + 7 bytes
class_dealloc(PyClassObject * 0x02da7ddc) line 114 + 62 bytes
_Py_Dealloc(_object * 0x02da7ddc) line 978 + 7 bytes
tupledealloc(PyTupleObject * 0x0371e4ac) line 151 + 93 bytes
_Py_Dealloc(_object * 0x0371e4ac) line 978 + 7 bytes
class_dealloc(PyClassObject * 0x0371e44c) line 114 + 62 bytes
_Py_Dealloc(_object * 0x0371e44c) line 978 + 7 bytes
instancemethod_dealloc(PyMethodObject * 0x0371e2ec) line 1634 + 62
bytes
_Py_Dealloc(_object * 0x0371e2ec) line 978 + 7 bytes
PyDict_Clear(_object * 0x0371e67c) line 539 + 108 bytes
dict_tp_clear(_object * 0x0371e67c) line 1156 + 9 bytes
delete_garbage(_gc_head * 0x0012cc94, _gc_head * 0x1e1dccf8
generation2) line 340 + 7 bytes
collect(_gc_head * 0x1e1dcce8 generation1, _gc_head * 0x1e1dccf8
generation2) line 416 + 13 bytes
collect_generations() line 476 + 15 bytes
_PyGC_Insert(_object * 0x056d592c) line 508
PyTuple_New(int 6) line 87 + 9 bytes
r_object(WFILE * 0x0012d770) line 498 + 9 bytes
r_object(WFILE * 0x0012d770) line 565 + 18 bytes
r_object(WFILE * 0x0012d770) line 502 + 9 bytes
r_object(WFILE * 0x0012d770) line 565 + 18 bytes
PyMarshal_ReadObjectFromFile(_iobuf * 0x00286908) line 620 + 9 bytes
read_compiled_module(char * 0x0012d7b8, _iobuf * 0x00286908) line 577
+ 9 bytes
load_source_module(char * 0x0012da70, char * 0x0012d914, _iobuf *
0x002868e8) line 740 + 19 bytes
load_module(char * 0x0012da70, _iobuf * 0x002868e8, char * 0x0012d914,
int 1) line 1227 + 17 bytes
import_submodule(_object * 0x1e1e8d48 __Py_NoneStruct, char *
0x0012da70, char * 0x0012da70) line 1755 + 33 bytes
load_next(_object * 0x1e1e8d48 __Py_NoneStruct, _object * 0x1e1e8d48
__Py_NoneStruct, char * * 0x0012db84, char * 0x0012da70, int *
0x0012da6c) line 1611 + 17 bytes
import_module_ex(char * 0x00000000, _object * 0x056aa62c, _object *
0x056aa62c, _object * 0x1e1e8d48 __Py_NoneStruct) line 1462 + 35 bytes
PyImport_ImportModuleEx(char * 0x056ab7fc, _object * 0x056aa62c,
_object * 0x056aa62c, _object * 0x1e1e8d48 __Py_NoneStruct) line 1503
+ 21 bytes
builtin___import__(_object * 0x00000000, _object * 0x056ae7dc) line 31
+ 21 bytes
call_builtin(_object * 0x052f4180, _object * 0x056ae7dc, _object *
0x00000000) line 2650 + 11 bytes
PyEval_CallObjectWithKeywords(_object * 0x052f4180, _object *
0x056ae7dc, _object * 0x00000000) line 2618 + 17 bytes
eval_code2(PyCodeObject * 0x056ae200, _object * 0x056aa62c, _object *
0x056aa62c, _object * * 0x00000000, int 0, _object * * 0x00000000, int
0, _object * * 0x00000000, int 0, _object * 0x00000000) line 1680 + 15
bytes
PyEval_EvalCode(PyCodeObject * 0x056ae200, _object * 0x056aa62c,
_object * 0x056aa62c) line 324 + 31 bytes
PyImport_ExecCodeModuleEx(char * 0x0012e090, _object * 0x056ae200,
char * 0x0012ddd8) line 495 + 17 bytes
load_source_module(char * 0x0012e090, char * 0x0012ddd8, _iobuf *
0x002868c8) line 758 + 17 bytes
load_module(char * 0x0012e090, _iobuf * 0x002868c8, char * 0x0012df34,
int 1) line 1227 + 17 bytes
import_submodule(_object * 0x1e1e8d48 __Py_NoneStruct, char *
0x0012e090, char * 0x0012e090) line 1755 + 33 bytes
load_next(_object * 0x1e1e8d48 __Py_NoneStruct, _object * 0x1e1e8d48
__Py_NoneStruct, char * * 0x0012e1a4, char * 0x0012e090, int *
0x0012e08c) line 1611 + 17 bytes
import_module_ex(char * 0x00000000, _object * 0x056a445c, _object *
0x056a445c, _object * 0x052522ec) line 1462 + 35 bytes
PyImport_ImportModuleEx(char * 0x056a24dc, _object * 0x056a445c,
_object * 0x056a445c, _object * 0x052522ec) line 1503 + 21 bytes
builtin___import__(_object * 0x00000000, _object * 0x0525f6fc) line 31
+ 21 bytes
call_builtin(_object * 0x052f4180, _object * 0x0525f6fc, _object *
0x00000000) line 2650 + 11 bytes
PyEval_CallObjectWithKeywords(_object * 0x052f4180, _object *
0x0525f6fc, _object * 0x00000000) line 2618 + 17 bytes
eval_code2(PyCodeObject * 0x056a4500, _object * 0x056a445c, _object *
0x056a445c, _object * * 0x00000000, int 0, _object * * 0x00000000, int
0, _object * * 0x00000000, int 0, _object * 0x00000000) line 1680 + 15
bytes
PyEval_EvalCode(PyCodeObject * 0x056a4500, _object * 0x056a445c,
_object * 0x056a445c) line 324 + 31 bytes
PyImport_ExecCodeModuleEx(char * 0x0012e6b0, _object * 0x056a4500,
char * 0x0012e3f8) line 495 + 17 bytes
load_source_module(char * 0x0012e6b0, char * 0x0012e3f8, _iobuf *
0x002868a8) line 758 + 17 bytes
load_module(char * 0x0012e6b0, _iobuf * 0x002868a8, char * 0x0012e554,
int 1) line 1227 + 17 bytes
import_submodule(_object * 0x1e1e8d48 __Py_NoneStruct, char *
0x0012e6b0, char * 0x0012e6b0) line 1755 + 33 bytes
load_next(_object * 0x1e1e8d48 __Py_NoneStruct, _object * 0x1e1e8d48
__Py_NoneStruct, char * * 0x0012e7c4, char * 0x0012e6b0, int *
0x0012e6ac) line 1611 + 17 bytes
import_module_ex(char * 0x00000000, _object * 0x056a270c, _object *
0x056a270c, _object * 0x1e1e8d48 __Py_NoneStruct) line 1462 + 35 bytes
PyImport_ImportModuleEx(char * 0x01b5441c, _object * 0x056a270c,
_object * 0x056a270c, _object * 0x1e1e8d48 __Py_NoneStruct) line 1503
+ 21 bytes
builtin___import__(_object * 0x00000000, _object * 0x0525b51c) line 31
+ 21 bytes
call_builtin(_object * 0x052f4180, _object * 0x0525b51c, _object *
0x00000000) line 2650 + 11 bytes
PyEval_CallObjectWithKeywords(_object * 0x052f4180, _object *
0x0525b51c, _object * 0x00000000) line 2618 + 17 bytes
eval_code2(PyCodeObject * 0x056a2080, _object * 0x056a270c, _object *
0x056a270c, _object * * 0x00000000, int 0, _object * * 0x00000000, int
0, _object * * 0x00000000, int 0, _object * 0x00000000) line 1680 + 15
bytes
PyEval_EvalCode(PyCodeObject * 0x056a2080, _object * 0x056a270c,
_object * 0x056a270c) line 324 + 31 bytes
PyImport_ExecCodeModuleEx(char * 0x0012ecd0, _object * 0x056a2080,
char * 0x0012ea18) line 495 + 17 bytes
load_source_module(char * 0x0012ecd0, char * 0x0012ea18, _iobuf *
0x00286888) line 758 + 17 bytes
load_module(char * 0x0012ecd0, _iobuf * 0x00286888, char * 0x0012eb74,
int 1) line 1227 + 17 bytes
import_submodule(_object * 0x1e1e8d48 __Py_NoneStruct, char *
0x0012ecd0, char * 0x0012ecd0) line 1755 + 33 bytes
load_next(_object * 0x1e1e8d48 __Py_NoneStruct, _object * 0x1e1e8d48
__Py_NoneStruct, char * * 0x0012ede4, char * 0x0012ecd0, int *
0x0012eccc) line 1611 + 17 bytes
import_module_ex(char * 0x00000000, _object * 0x056a110c, _object *
0x056a110c, _object * 0x1e1e8d48 __Py_NoneStruct) line 1462 + 35 bytes
PyImport_ImportModuleEx(char * 0x056a322c, _object * 0x056a110c,
_object * 0x056a110c, _object * 0x1e1e8d48 __Py_NoneStruct) line 1503
+ 21 bytes
builtin___import__(_object * 0x00000000, _object * 0x052489cc) line 31
+ 21 bytes
call_builtin(_object * 0x052f4180, _object * 0x052489cc, _object *
0x00000000) line 2650 + 11 bytes
PyEval_CallObjectWithKeywords(_object * 0x052f4180, _object *
0x052489cc, _object * 0x00000000) line 2618 + 17 bytes
eval_code2(PyCodeObject * 0x056a1160, _object * 0x056a110c, _object *
0x056a110c, _object * * 0x00000000, int 0, _object * * 0x00000000, int
0, _object * * 0x00000000, int 0, _object * 0x00000000) line 1680 + 15
bytes
PyEval_EvalCode(PyCodeObject * 0x056a1160, _object * 0x056a110c,
_object * 0x056a110c) line 324 + 31 bytes
PyImport_ExecCodeModuleEx(char * 0x0012f2f0, _object * 0x056a1160,
char * 0x0012f038) line 495 + 17 bytes
load_source_module(char * 0x0012f2f0, char * 0x0012f038, _iobuf *
0x00286868) line 758 + 17 bytes
load_module(char * 0x0012f2f0, _iobuf * 0x00286868, char * 0x0012f194,
int 1) line 1227 + 17 bytes
import_submodule(_object * 0x1e1e8d48 __Py_NoneStruct, char *
0x0012f2f0, char * 0x0012f2f0) line 1755 + 33 bytes
load_next(_object * 0x1e1e8d48 __Py_NoneStruct, _object * 0x1e1e8d48
__Py_NoneStruct, char * * 0x0012f404, char * 0x0012f2f0, int *
0x0012f2ec) line 1611 + 17 bytes
import_module_ex(char * 0x00000000, _object * 0x00000000, _object *
0x00000000, _object * 0x00000000) line 1462 + 35 bytes
PyImport_ImportModuleEx(char * 0x005b27e8 `string', _object *
0x00000000, _object * 0x00000000, _object * 0x00000000) line 1503 + 21
bytes
PyImport_ImportModule(char * 0x005b27e8 `string') line 1436 + 20 bytes

After each time I call the method and the module using the methods
above I make sure that they are decremented using Py_XDECREF( module)
and Py_XDECREF( method ).

Any ideas why it crashes would be warmly received.

Thanks.

Adrian.



More information about the Python-list mailing list