freelanceprogrammers.org Forum Index » Delphi
question about using multiple threads with pythonfordelphi
Joined: 16 Nov 2005
Posts: 1
question about using multiple threads with pythonfordelphi
Hello,
I am trying to use pythonfordelphi with multiple threads but I can`t
seem to get it to work. I am creating a thread class which is a
decendent of TPythonThread and I put the calls to the python api in
the ExecuteWithPython method. I set up the threads similar to the
threads demo. However, when i do this the first thread that is
created seems to get blocked somewhere during the first execution of
ExecuteWithPython and it never returns.
Is there some trick to doing this? I wrote the following code in C
and it seemed to work fine but it doesn`t work in P4D because one of
the threads seems to get blocked.
Any help is appreciated.
brian
-------------------------------------------------------------------------
DWORD WINAPI PythonThread (LPDWORD paramPtr)
{
PyThreadState *myThreadState;
PyInterpreterState *mainInterpreterState;
PyEval_AcquireLock();
mainInterpreterState=mainThreadState->interp;
myThreadState = PyThreadState_New(mainInterpreterState);
PyEval_ReleaseLock();
while (TRUE)
{
// grab the global interpreter lock
PyEval_AcquireLock();
// swap in my thread state
PyThreadState_Swap(myThreadState);
// execute some python code
PyRun_SimpleString ("x+=1");
PyRun_SimpleString ("print x");
// clear the thread state
PyThreadState_Swap(NULL);
// release our hold on the global interpreter
PyEval_ReleaseLock();
}
// cleanup code ....
}
int main()
{
Py_Initialize();
PyEval_InitThreads ();
mainThreadState = PyThreadState_Get();
// create 2 instances of PythonThread
}
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







