Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,18 +1,15 @@
|
|||
import time
|
||||
|
||||
def intrptWIN():
|
||||
procDone = False
|
||||
n = 0
|
||||
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
|
||||
|
||||
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
|
||||
counter()
|
||||
|
|
|
|||
|
|
@ -1,29 +1,18 @@
|
|||
import signal, time, threading
|
||||
done = False
|
||||
n = 0
|
||||
import time
|
||||
|
||||
def counter():
|
||||
global n, timer
|
||||
n += 1
|
||||
print n
|
||||
timer = threading.Timer(0.5, counter)
|
||||
timer.start()
|
||||
def intrptWIN():
|
||||
procDone = False
|
||||
n = 0
|
||||
|
||||
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()
|
||||
while not procDone:
|
||||
try:
|
||||
time.sleep(0.5)
|
||||
n += 1
|
||||
print n
|
||||
except KeyboardInterrupt, e:
|
||||
procDone = True
|
||||
|
||||
t1 = time.time()
|
||||
intrptUNIX()
|
||||
intrptWIN()
|
||||
tdelt = time.time() - t1
|
||||
print 'Program has run for %5.3f seconds.' % tdelt
|
||||
|
|
|
|||
|
|
@ -1,23 +1,29 @@
|
|||
import time, signal
|
||||
import signal, time, threading
|
||||
done = False
|
||||
n = 0
|
||||
|
||||
class WeAreDoneException(Exception):
|
||||
pass
|
||||
def counter():
|
||||
global n, timer
|
||||
n += 1
|
||||
print n
|
||||
timer = threading.Timer(0.5, counter)
|
||||
timer.start()
|
||||
|
||||
def sigIntHandler(signum, frame):
|
||||
signal.signal(signal.SIGINT, signal.SIG_DFL) # resets to default handler
|
||||
raise WeAreDoneException
|
||||
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()
|
||||
|
||||
try:
|
||||
signal.signal(signal.SIGINT, sigIntHandler)
|
||||
n = 0
|
||||
while True:
|
||||
time.sleep(0.5)
|
||||
n += 1
|
||||
print n
|
||||
except WeAreDoneException:
|
||||
pass
|
||||
|
||||
intrptUNIX()
|
||||
tdelt = time.time() - t1
|
||||
print 'Program has run for %5.3f seconds.' % tdelt
|
||||
|
|
|
|||
23
Task/Handle-a-signal/Python/handle-a-signal-4.py
Normal file
23
Task/Handle-a-signal/Python/handle-a-signal-4.py
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue