I want to write a python command line script that will accept user input while simultaneously running another function or script at constant intervals. I have written some pseudo-code below to show what I am aiming for:
def main():
threading.Timer(1.0, function_to_run_in_background).start()
while True:
command = raw_input("Enter a command >>")
if command.lower() == "quit":
break
def function_to_run_in_background():
while True:
print "HI"
time.sleep(2.0)
if __name__ == "__main__":
main()
I have tried to make something along these lines work, but usually what happens is that the function_to_run_in_background only runs once and I would like it to run continuously at a specified interval while the main thread of the program accepts user input. Is this close to what I am thinking of or is there a better way?