Coldspeed made the comment that you could put this at the top of your file:
if input_variable != 'ready':
sys.exit()
That will exit the program if it doesn't get the expected variable. However, I personally prefer a different paradigm: put your program in a main function, and conditionally return:
def main(*argv):
if input_variable != 'ready':
return
[program]
if __name__ == '__main__':
main(*sys.argv)
There are a number of reasons to put your program in a main
function. The most notable is that it allows you to import the file without actually executing it, which can be very useful for debugging.