Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from mango.debug import debug
2from time import time
5class start():
6 """Set walltime of the program for clean exiting."""
8 def __init__(self, walltime):
9 self.start_time = time()
10 self.walltime = walltime
11 self.finishtime = self.start_time + self.walltime
14class end():
15 """Make sure the program exits within the walltime."""
17 def __init__(self, startinst):
18 self.__dict__.update(startinst.__dict__)
20 def gettimeleft(self):
21 """Return time left in run."""
22 self.current_time = time()
23 self.timeleft = self.finishtime - self.current_time
24 return self.timeleft
26 def gettimegone(self):
27 self.current_time = time()
28 self.timegone = self.current_time - self.start_time
29 return self.timegone
31 def finished(self):
32 """Return current run time."""
33 self.finished = time()
34 self.timetaken = self.finished - self.start_time
35 return "Completed in {:.2f} seconds".format(self.timetaken)
38class grace():
40 def __init__(self, stats):
41 """Allow time for file saving."""
42 self.time = 10 * len(stats) if 10 * len(stats) > 120 else 120
45class _time():
46 """Time and iteration storage."""
48 @debug(['time'])
49 def __init__(self, dt, t0):
50 self.dt = dt
51 self.time = t0
52 self.iter = 0
54 @debug(['time'])
55 def time_update(self):
56 self.time += self.dt
57 self.iter += 1
60if __name__ == '__main__':
61 pass