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

16 lines
297 B
Python
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
import time
2015-02-20 00:35:01 -05:00
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
2013-04-10 21:29:02 -07:00
2015-02-20 00:35:01 -05:00
counter()