This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ugodiggi
Recipients
Date 2005-04-30.19:03:33
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
The following code crashes about 1/3 of the times. 

My platform is Python 2.4.1 on WXP (I tried the release
version from the msi and the debug version built by me). 
I can reproduce the same behavior on another wxp
system, under python 2.4. 

The crash happens (in the python thread) while the main
thread is in Py_Finalize. 
I traced the crash to _Py_ForgetReference(op) in
object.c at line 1847, where I have op->_ob_prev == NULL. 

The open file seems to be the issue, since if I remove
all the references to the file I cannot get the program
to crash.

Cheers and ciao 

Ugo 

////////////////////////// TestPyThreads.cpp
////////////////////////// 
#include <windows.h> // Sleep
#include "Python.h" 

int main() 
{ 
        PyEval_InitThreads(); 
        Py_Initialize(); 
        PyGILState_STATE main_restore_state =
PyGILState_UNLOCKED; 
        PyGILState_Release(main_restore_state); 

        // start the thread 
        { 
                PyGILState_STATE state =
PyGILState_Ensure(); 
                int trash = PyRun_SimpleString( 
                                "import thread\n" 
                                "import time\n" 
                                "def foo():\n" 
                                "  f =
open('pippo.out', 'w', 0)\n" 
                                "  i = 0;\n" 
                                "  while 1:\n" 
                                "    f.write('%d\\n'%i)\n" 
                                "    time.sleep(0.01)\n" 
                                "    i += 1\n" 
                                "t =
thread.start_new_thread(foo, ())\n" 
                                ); 
                PyGILState_Release(state); 
        } 

        // wait 300 ms 
        Sleep(300); 

        PyGILState_Ensure(); 
        Py_Finalize(); 
        return 0; 
} 
 
History
Date User Action Args
2007-08-23 14:31:24adminlinkissue1193099 messages
2007-08-23 14:31:24admincreate