I have a CLI program in python that will run files. However, if a program is run that never stops, I want the user to be able to 'kill' that program, but not the whole script. The input for stopping the script could be the push of a certain key on the keyboard, I really have no clue how to do this and I couldn't find any answers here. I am using a os.system process, here is a snippet of my code and an example:
if os.path.isfile('../file'):
cmd = os.path.join(os.getcwd(), '../file')
os.system('{} {}'.format('python', cmd))
print('Process finished')
And file contains the following code:
while True:
print("Do stuff")
Please note that I cannot edit 'file' and I want to be able to stop the os.system process with a key pressed without killing the entire main script.