How to stop a running embedded interpreter?

Dirk Runge egnur at t-online.de
Mon Sep 18 11:32:21 EDT 2006


Hi!

I have embedded Python in an C++ App.
The Python-Interpreter is running in its own
Thread (I'm using PThreads).

I use PyRun_SimpleString to run Python-Code that the user entered
in an editorwindow.
I want the user to be able to stop the execution of
Python-Code (e.g. using a Cancel-Button).
Unfortunately I can't find a way to do this.

Of course, I can kill the Interpreter-Thread forcibly with 
pthread_cancel() but the App will crash if I call any Python API-
Function afterwards.

I thought about starting 2 Threads in Python: One thread checks for a 
stop condition (by calling a C-function that checks the Cancel-Button) 
and the user-code runs in a second thread. The Problem with this 
approach is that there seems to be no possibility for one Python-thread 
to kill another.
I don't want the user to have to check fo a stop condition himself either.

Any help is greatly appreciated.

Regards,
Dirk



More information about the Python-list mailing list