I have a long computation that needs to be repeated many times with different input. I want to limit each repetition to, say, a minute. Using alarm means that if I try to manually interrupt the whole thing, it will just assume that one repetition timed out. Is there a solution that doesn't involve restarting the worksheet?
while True:
alarm(60)
try:
do_long_computation(random())
except KeyboardInterrupt:
continue
alarm(0)