I would like to create a function keep_running that I could define based on input to either be sensitive to the time that it had been running or the number of iterations. I can't seem to come up with a pythonic way to do the iterations without decrementing the counter outside of the function, e.g.:
def keep_running(ttl):
return ttl > 0
ttl = 1
while keep_running(ttl):
do_stuff()
ttl -= 1
Is there a better way to do this, preferably completely within the function keep_running?