C++ and Python: how can I make it stop?

Phil Hornby 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.

eg.

import gui

def a_callback():
	# do something

def main():

	# do some initialisation

	while not gui.Stop():
		# so something

	# do some shutdown

It is a fairly simple structure but it did work fairly well.

HTH

Phil






More information about the Python-list mailing list