1import time
2import sys
3
4time_start = time.time()
5seconds = 0
6minutes = 0
7
8running = True
9
10while running:
11 try:
12 sys.stdout.write("\r{minutes} Minutes {seconds} Seconds".format(minutes=minutes, seconds=seconds))
13 sys.stdout.flush()
14 time.sleep(1)
15 seconds = int(time.time() - time_start) - minutes * 60
16 if seconds >= 60:
17 minutes += 1
18 seconds = 0
19 except KeyboardInterrupt as e:
20 running = False
1
2
3import time
4
5now = time.time()
6future = now + 10
7while time.time() < future:
8 # do stuff
9 pass