Issue 9828: Repeated Py_Initialize and Py_Finalize usage brings fatal error? (original) (raw)

When I ran the code in #6869 () on py3k, I noticed Fatal Python error occurs.

Actually, I need to copy created executable file into

PC/VC6 directoly where python32_d.dll exists. Otherwise,

the error "encoding.utf-8 was not found" occured even if

PC/VC6 was added to environment variable PATH. But probably

it is another issue.

E:\python-dev\py3k\PC\VC6>foo --- 0 --- [34859 refs] --- 1 --- Fatal Python error: drop_gil: wrong thread state

... And here is stacktrace.

_NMSG_WRITE(int 10) line 221 abort() line 44 + 7 bytes Py_FatalError(const char * 0x1e371878) line 2109 drop_gil(_ts * 0x00920d90) line 321 + 10 bytes PyEval_SaveThread() line 424 + 6 bytes 0012ff30() PyCFunction_Call(_object * 0x00b99378, _object * 0x00afcc40, _object * 0x00000000) line 89 + 9 bytes PyObject_Call(_object * 0x00b99378, _object * 0x00afcc40, _object * 0x00000000) line 2149 + 15 bytes call_function_tail(_object * 0x00b99378, _object * 0x00afcc40) line 2181 + 15 bytes _PyObject_CallMethod_SizeT(_object * 0x00bf6838, char * 0x1e332898, char * 0x00000000) line 2297 + 13 bytes io_open(_object * 0x00c17f78, _object * 0x00ae0f88, _object * 0x00000000) line 423 + 16 bytes PyCFunction_Call(_object * 0x00b0cab8, _object * 0x00ae0f88, _object * 0x00000000) line 84 + 15 bytes PyObject_Call(_object * 0x00b0cab8, _object * 0x00ae0f88, _object * 0x00000000) line 2149 + 15 bytes call_function_tail(_object * 0x00b0cab8, _object * 0x00ae0f88) line 2181 + 15 bytes PyObject_CallMethod(_object * 0x00bf6138, char * 0x1e3d6abc, char * 0x1e3d6ab4) line 2258 + 13 bytes create_stdio(_object * 0x00bf6138, int 0, int 0, char * 0x1e3d6968, char * 0x00000000, char * 0x00000000) line 808 + 48 bytes initstdio() line 931 + 28 bytes Py_InitializeEx(int 1) line 303 + 5 bytes Py_Initialize() line 314 + 7 bytes main() line 10 + 8 bytes mainCRTStartup() line 206 + 25 bytes KERNEL32! 77e789d5()

Because first run succeeded, Py_Finalize might not do enough work to reset thread state, I guess.

I didn't try this on other platforms. (thread_nt.h was used here)

I can't reproduce under Linux. Is 3.1 also affected? Can you try the following patch:

Index: Python/pythonrun.c

--- Python/pythonrun.c (révision 84718) +++ Python/pythonrun.c (copie de travail) @@ -219,6 +219,8 @@

 /* auto-thread-state API, if available */

#ifdef WITH_THREAD

#endif /* WITH_THREAD */