RosettaCodeData/Task/Handle-a-signal/Python/handle-a-signal-1.py

16 lines
297 B
Python
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
import time
def counter():
n = 0
t1 = time.time()
while True:
try:
time.sleep(0.5)
n += 1
print n
except KeyboardInterrupt, e:
print 'Program has run for %5.3f seconds.' % (time.time() - t1)
break
counter()