I made a super rudimentary stopwatch in python, just to get myself more acclimated with it, (It's my first programming language)and I've been trying to get the code to stop running when a key is pressed (using keyboard interrupt) but the code basically ignores keyboard interrupt and keeps going on forever. (here's my code for reference)
# Time
import time
import sys
timeLoop = True
# Variables to keep track and display
Sec = 0
Min = 0
Hour = 0
# Begin Process
timeloop = True
while timeloop == True:
try:
Sec += 1
print(str(Hour) + " Hrs " + str(Min) + " Mins " + str(Sec) + " Sec ")
time.sleep(1)
if Sec == 60:
Sec = 0
Min += 1
print(str(Min) + " Minute")
if Min == 60:
Sec = 0
Min = 0
Hour += 1
print(str(Hour) + " Hours")
except KeyboardInterrupt:
sys.exit(0)