I have a homepage calling a thread object, the object is making some measurements, but sometimes if something goes wrong I want the homepage to stop the thread.
I am doing something like this Is there any way to kill a Thread in Python?
but this post says
The thread should check the stop flag at regular intervals.
is there a smart way to do that?
My code is making some setup, then is has a loop for each place it has to measure, and in that loop there is another loop for each time it has to measure each place.
I have been doing something like this:
def run(self):
if EXIT is False:
SETUP
for place in places:
if EXIT is False:
for measurement in measurements:
if EXIT is False:
measure()
else:
break
else:
self.stop()
else:
self.stop()
This is only code example, I want a more beautiful way to check the exit request, and not use all the if statements
Thank you