embed interpreter and thread

François Sénéquier francois.senequier at voila.fr
Tue Dec 3 08:42:42 EST 2002


Hi,

I have embedded the python interpreter (2.2.2) into a C program (Visual C++ / Windows platform).
I have extended the python interpreter using methods directly mapped of my C methods.
The purpose is to control the C application with scripts written in python.

As I want to execute the script "cmdPY" and stop it any time so I put the execution of the script into a thread.
At the same time, I have just one acitve thread (ie just one active python interpeter).

>>> This is the sample code of the thread :

DWORD WINAPI ThreadPython(LPVOID lpParam)
{
Py_Initialize();
PyRun_SimpleString((char *) lpParam);
Py_Finalize();
ExitThread(res);
return 0;
}

ThreadHD = CreateThread(NULL, 0, ThreadPython, (LPVOID) cmdPY, 0, &ThreadID);

>>> Now the code to stop the thread is :

TerminateThread(ThreadHD, -1)

Then the script is correctly started and correctly stopped, but when I try to start a new thread
with the same script (or not) I have the following message into a dialog box :

Microsoft Visual C++ Runtime library
Runtime Error!
...
Abnormal program termination

I suppose that's because my procedure to stop the python interpreter (killing directly the thread) is too hard but I don't
know how to stop properly the interpreter before killing the thread ?

Thanks
------------------------------------------

Faites un voeu et puis Voila ! www.voila.fr 





More information about the Python-list mailing list