C++ and Python: how can I make it stop?
phil.hornby at accutest.co.uk
Tue Dec 30 14:28:20 CET 2003
I did something similar a while ago...
My simple solution was this:
As part of my application API I exposed a function "Stop()" in my app I had
2 threads - one that was the GUI etc and another that Python is executed
in( using PyRun_SimpleString ).
It then becomes the responsibility of the script to ensure that it calls
"Stop()" regularly to check whether it should stop executing... We defined a
structure with a script containing a function "main()" that was executed by
the main app; this function contained a simple loop checking the status -
most of the functionality we had relied on callbacks into the script's
context from other threads of execution.
# do something
# do some initialisation
while not gui.Stop():
# so something
# do some shutdown
It is a fairly simple structure but it did work fairly well.
More information about the Python-list