TL;DR
I want a script (Python-3.x) to move to the last output if it satisfies a condition, pausing the loop that is generating outputs so I can inspect the result, but I also want the script to keep calculating if I'm not there. For this, I propose a "dummy" input line.
Context
I have a long script that calculate different possible combinations for a set of parameters, then solve differential equations using the parameters and finally compare analytical results and generate plots.
Whenever there's an "interesting result" (that matches several conditions), which usually happens once in O(10^3) tries, I ask the script to do the following:
- Stop the loop that is extracting and testing one configuration at a time, from many possible combinations calculated, e.g.,
len(combs) = O(10^7) - Store the "interesting" array with the parameters using
np.saveinside a.npyfile. - Asking for an
input, e.g.,input('coincidence encountered, please press enter!'); printing a fragment of the results inmediately after. - Asking to generate another set of combinations, and start looping, extracting and testing one at the time (go back to 1). This repeatedly for a range of tries.
Why 3 (asking for input)? because in every test (of interest or not) there's a long enough input (two plots), so it's not that simple to examine through every plot, altough I want to print the "non interesting results" anyways.
The question
... is: what can I do to ask for the input anyways, so my scrollbar gets dragged to the output I want to view if I'm close to the screen, but also imposing a max_time to press enter, to cover situations like when I'm not close to the PC but just running the script? What else could I do? e.g., not using input() but another unknown function (to me).
An example
import random
def a_function():
do_something = random.randint(0,100)
return do_something
l=[]
for i in range(10):
n = a_function()
if n > 90:
print(n)
l.append(n)
input('press enter') #if 20 seconds AFK, omitting this line input
The goal is to achieve the task (ideas behind steps 1, 2, 3, 4); of course, if you think there are better ways than asking for input I'd be really happy to know about any other ideas.