def timeRemaining(seconds=0):
""" Function to be used with 'while' """
global _timers
if seconds == 0: return True
now = time.time()
stack = traceback.extract_stack()
filename, line_no, q1, q2 = stack[-2]
if filename.startswith("<pyshell"):
filename = "pyshell"
if (filename, line_no) not in _timers:
_timers[(filename, line_no)] = (now, seconds)
return True
start, duration = _timers[(filename, line_no)]
if seconds != duration:
_timers[(filename, line_no)] = (now, seconds)
return True
if now - start > duration:
del _timers[(filename, line_no)]
return False
else:
return True
评论列表
文章目录