I have a program that does some work in a timed while loop like so:
import time
While True:
do something
time.sleep(60)
I would like to be able to break out of the loop nicely from the console and save some data on the way out. The solution I have thought of is to create a file when I want the program to quit and check for the file inside the loop like so.
from os.path import exists
While True:
do something
if exists('exit.txt'):
print('exiting')
clean_up()
time.sleep(60)
Is there a better way?