Jump to content

Handle a signal: Difference between revisions

m (MATLAB: Fixed works with templates)
Line 739:
 
=={{header|Python}}==
Simple version
<lang python>import time
 
def counter():
n = 0
t1 = time.time()
while True:
try:
time.sleep(0.5)
n += 1
print n
except KeyboardInterrupt, e:
break
print 'Program has run for %5.3f seconds.' % (time.time() - t1)
 
counter()</lang>
The following example should work on all platforms.
<lang python>import time
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.