noiftimer.stopwatch

 1import threading
 2import time
 3
 4from printbuddies import print_in_place
 5
 6from noiftimer import Timer
 7
 8QUIT = False
 9
10
11def input_(prompt: str = ""):
12    global QUIT
13    value = input(prompt)
14    if value == "q":
15        QUIT = True
16
17
18def stopwatch():
19    input_thread = threading.Thread(target=input_, daemon=True)
20    input_("Press enter to start. ")
21    if not QUIT:
22        print("Press enter to stop.")
23    timer = Timer(subsecond_resolution=False).start()
24    input_thread.start()
25    while input_thread.is_alive() and not QUIT:
26        print_in_place(f" {timer.elapsed_str} ")
27        time.sleep(1)
28
29
30def main():
31    print("Press 'q' and then enter to quit at any time.")
32    while not QUIT:
33        stopwatch()
34
35
36if __name__ == "__main__":
37    main()
def input_(prompt: str = ''):
12def input_(prompt: str = ""):
13    global QUIT
14    value = input(prompt)
15    if value == "q":
16        QUIT = True
def stopwatch():
19def stopwatch():
20    input_thread = threading.Thread(target=input_, daemon=True)
21    input_("Press enter to start. ")
22    if not QUIT:
23        print("Press enter to stop.")
24    timer = Timer(subsecond_resolution=False).start()
25    input_thread.start()
26    while input_thread.is_alive() and not QUIT:
27        print_in_place(f" {timer.elapsed_str} ")
28        time.sleep(1)
def main():
31def main():
32    print("Press 'q' and then enter to quit at any time.")
33    while not QUIT:
34        stopwatch()