I know this has been seen before but it is not making too much sense (after
reading many posts). It all appears to work fine but then dies after about
40 invocations.
My app has Python embedded, it is embedded as part of a dll which
initializes python and finalizes on load and unload (see below). When a
script needs to be run, I create a new thread, let the script complete and
close the thread.
The thread contains the following type arrangement:
PythonThread()
{
hScriptFile = OpenScriptFile( m_szActiveScrip t);
PyEval_AcquireL ock();
pInterpreter = Py_NewInterpret er();
Py_SetProgramNa me(szModuleFile Name);
PyRun_SimpleFil e(hScriptFile,m _szActiveScript );
PyErr_Clear();
Py_EndInterpret er(pInterpreter );
PyEval_ReleaseL ock();
}
This appears to work fine accept that after around 30-40 invocations I
always get the "Invalid thread state for this thread". ie the app and dll
stay loaded and I click my "run" button manually about 40 times. In this
test it is a simple "hello world" type script. The size of the script does
not appear to matter.
The dll is coded something like this:
DllLoad()
{
Py_Initialize() ;
PyEval_InitThre ads();
m_mainThreadSta te = PyThreadState_G et();
PyEval_ReleaseL ock();
}
DllUnload() (not called as part of this test)
{
PyEval_AcquireL ock();
PyThreadState_S wap(m_mainThrea dState);
Py_Finalize();
}
The app has been designed to allow a second interpreter to run independently
(thus the need for multiple thread support) and this also appears to work
fine, but for this test only this one thread was used. I have a compiled
version of 2.4.2.
Any ideas would be appreciated.
Martin
reading many posts). It all appears to work fine but then dies after about
40 invocations.
My app has Python embedded, it is embedded as part of a dll which
initializes python and finalizes on load and unload (see below). When a
script needs to be run, I create a new thread, let the script complete and
close the thread.
The thread contains the following type arrangement:
PythonThread()
{
hScriptFile = OpenScriptFile( m_szActiveScrip t);
PyEval_AcquireL ock();
pInterpreter = Py_NewInterpret er();
Py_SetProgramNa me(szModuleFile Name);
PyRun_SimpleFil e(hScriptFile,m _szActiveScript );
PyErr_Clear();
Py_EndInterpret er(pInterpreter );
PyEval_ReleaseL ock();
}
This appears to work fine accept that after around 30-40 invocations I
always get the "Invalid thread state for this thread". ie the app and dll
stay loaded and I click my "run" button manually about 40 times. In this
test it is a simple "hello world" type script. The size of the script does
not appear to matter.
The dll is coded something like this:
DllLoad()
{
Py_Initialize() ;
PyEval_InitThre ads();
m_mainThreadSta te = PyThreadState_G et();
PyEval_ReleaseL ock();
}
DllUnload() (not called as part of this test)
{
PyEval_AcquireL ock();
PyThreadState_S wap(m_mainThrea dState);
Py_Finalize();
}
The app has been designed to allow a second interpreter to run independently
(thus the need for multiple thread support) and this also appears to work
fine, but for this test only this one thread was used. I have a compiled
version of 2.4.2.
Any ideas would be appreciated.
Martin
Comment