I am creating a GUI with Tkinter in Python for a serial device that controls two moving axis. I have setup a tkinter window with buttons, Entries,...
One crucial part of the project is to stop the movement of an axis when a button is clicked. Let's look at this example: I can measure the absolute position of one axis by sending a command via the serial port, yet this measuring process may take up to two minutes, thus my whole program (including the GUI) waits for the serial device to feedback the position. I need it to wait for the response, but my GUI should still be responsive to issue the stop move command. I started working with multithreading, yet with no success. It seems like the thread is not being stopped.
Here are the code snippets:
global cPMthread
cPMthread = threading.Thread(target = doMeasuring, args = (getPort(), axis, steps))
cPMthread.start()
This is being called when the button to start the measuring is pressed.
def doMeasuring(port, axis, *therest):
global cPMthread
cPMthread = threading.currentThread()
if getattr(cPMthread, "do_run", True):
currentPosition = Agilis.measureCurrentPosition(port, axis)
This starts the new thread.
def stopMove(port, axis):
global cPMthread
print(cPMthread, "trying to stop the process")
cPMthread.do_run = False
And here I try to set the flag to stop the process.
Thanks for any advice