A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2005-April/052995.html below:

[Python-Dev] Problem with embedded python

[Python-Dev] Problem with embedded pythonUgo Di Girolamo Ugo_DiGirolamo at invision.iip.com
Tue Apr 26 23:15:38 CEST 2005
I have the following code, that seems to make sense to me. 


However, it 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, both downloaded today to 
have the latest version). 


The crash happens 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.


What am I doing wrong? I'm definitely not too sure about the way I'm 
handling the GIL. 


Thanks in adv for any suggestion/ comment


Cheers and ciao 


Ugo 


////////////////////////// TestPyThreads.py ////////////////////////// 
#include <windows.h> 
#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; 

} 
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4