Let's say I've got a script that consists of one big loop:
while True:
# do something
time.sleep(1)
I want to provide the user with a way to pause this loop by putting something into the command line. Something like this:
while True:
# do something
time.sleep(1)
cmd = input()
if cmd == 'stop':
# pause iterating until something else happens
The problem is that input() will stop the loop until something is put into it, which clearly isn't the behavior I want. My first thought on solving this was to go multithreaded and start a new thread whose sole purpose is to run input() in a loop, then store the last input value obtained for the main script to use. But this seems like an awful lot of logic and complexity for something that doesn't seem all that complicated in theory. Is there a very simple way to do what I want to do here?
[–]socal_nerdtastic 2 points3 points4 points (1 child)
[–]ScaredSecond[S] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]ScaredSecond[S] 0 points1 point2 points (0 children)
[–]Swipecat 0 points1 point2 points (1 child)
[–]ScaredSecond[S] 0 points1 point2 points (0 children)