Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,15 @@
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()

View file

@ -0,0 +1,18 @@
import time
def intrptWIN():
procDone = False
n = 0
while not procDone:
try:
time.sleep(0.5)
n += 1
print n
except KeyboardInterrupt, e:
procDone = True
t1 = time.time()
intrptWIN()
tdelt = time.time() - t1
print 'Program has run for %5.3f seconds.' % tdelt

View file

@ -0,0 +1,29 @@
import signal, time, threading
done = False
n = 0
def counter():
global n, timer
n += 1
print n
timer = threading.Timer(0.5, counter)
timer.start()
def sigIntHandler(signum, frame):
global done
timer.cancel()
done = True
def intrptUNIX():
global timer
signal.signal(signal.SIGINT, sigIntHandler)
timer = threading.Timer(0.5, counter)
timer.start()
while not done:
signal.pause()
t1 = time.time()
intrptUNIX()
tdelt = time.time() - t1
print 'Program has run for %5.3f seconds.' % tdelt

View file

@ -0,0 +1,23 @@
import time, signal
class WeAreDoneException(Exception):
pass
def sigIntHandler(signum, frame):
signal.signal(signal.SIGINT, signal.SIG_DFL) # resets to default handler
raise WeAreDoneException
t1 = time.time()
try:
signal.signal(signal.SIGINT, sigIntHandler)
n = 0
while True:
time.sleep(0.5)
n += 1
print n
except WeAreDoneException:
pass
tdelt = time.time() - t1
print 'Program has run for %5.3f seconds.' % tdelt