I am running sequential code in a loop that is doing various computations, and occasionally printing out results that I monitor in the console.
What I'd like to do is be able to hit keyboard buttons, while the program is running, and then save and process that input (e.g. as a command to change some parameter) on the next start iteration of that loop.
Here's the structure of the code I'm running:
for i in range(0, itrs):
# ideally at the start of each loop:
# check to see if user pressed keybutton during prev loop itr,
# but don't wait / poll for it!
# userKeyInput = checkIfUserPressedKey()
# param = modify(userKeyInput)
doSequentialComputation(param)
Would the solution involve some notion of threading or interrupt? I could probably come up with a solution that involves file I/O, which wouldn't be terrible, but I was thinking maybe Python has something simpler that would work.