How to stop a running embedded interpreter?

D

Dirk Runge

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top