def exit():
"""Dummy implementation of thread.exit()."""
raise SystemExit
python类exit()的实例源码
def retrieveThread(optDic,
taskCtrl,
dummy):
"""
"""
info(4,"Entering retrieveThread(%s) ..." % getThreadName())
client = testClient().parseSrvList(optDic["servers"][NGAS_OPT_VAL])
while (1):
nextFileId = taskCtrl.getNextFileId()
if (not nextFileId): thread.exit()
nextFileId = nextFileId[:-1]
info(1,"Next File ID: %s" % nextFileId)
try:
fileSize, fileObj = client.retrieveFileObj(nextFileId)
sizeRemain = fileSize
while (sizeRemain):
if (sizeRemain < BLOCK_SIZE):
reqSize = sizeRemain
else:
reqSize = BLOCK_SIZE
buf = fileObj.read(reqSize)
sizeRemain -= len(buf)
taskCtrl.incBytesRecv(fileSize)
except Exception, e:
error("Error retrieving file with ID: %s - skipping. Error: %s" %\
(nextFileId, str(e)))
def archiveThread(testObj,
no,
inc,
dummy):
"""
Archive a file X times.
testObj: Reference to instance of ngamsTestSuite object (ngamsTestSuite).
no: Number allocated to thread (integer).
inc: Increment ARCFILE keyword before submitting each Archive Request
(0|1/integer).
Returns: Void
"""
if (inc):
filename = "tmp/ngamsArchiveStressTest_%d.fits" % no
cpFile("src/TinyTestFile.fits", filename)
incArcfile(filename, step=(100 * no))
else:
filename = "src/TinyTestFile.fits"
testStr = TST_STR1 % os.path.basename(filename)
for n in range(5):
if (not RUN_TEST):
THREAD_STAT[no] = "STOPPED"
break
if (inc): incArcfile(filename)
statObj = sendPclCmd(auth=AUTH).archive(filename)
if (statObj.getMessage() != testStr):
THREAD_STAT[no] = "FAILURE: Archive Request failed"
THREAD_STAT[no] = "SUCCESS"
thread.exit()
def start_new_thread(function, args, kwargs={}):
"""Dummy implementation of thread.start_new_thread().
Compatibility is maintained by making sure that ``args`` is a
tuple and ``kwargs`` is a dictionary. If an exception is raised
and it is SystemExit (which can be done by thread.exit()) it is
caught and nothing is done; all other exceptions are printed out
by using traceback.print_exc().
If the executed function calls interrupt_main the KeyboardInterrupt will be
raised when the function returns.
"""
if type(args) != type(tuple()):
raise TypeError("2nd arg must be a tuple")
if type(kwargs) != type(dict()):
raise TypeError("3rd arg must be a dict")
global _main
_main = False
try:
function(*args, **kwargs)
except SystemExit:
pass
except:
_traceback.print_exc()
_main = True
global _interrupt
if _interrupt:
_interrupt = False
raise KeyboardInterrupt
def exit():
"""Dummy implementation of thread.exit()."""
raise SystemExit
def cancel_transfer(self):
if self.cancel_button["text"] == "Cancel":
# If the cancel button says "Cancel" then we want to set the exit flag to True
self._thread_should_exit = True
elif self.cancel_button["text"] == "Clear":
# Otherwise if the cancel button says "Clear" we have to remove the upload frame
self.grid_forget()
def set_edge(self,value,callback,debouncingtime=0):
if self.fd!=None:
set_edge(self.kernel_id,value)
thread.start_new_thread(self.wait_edge,(self.fd,callback,debouncingtime))
return
else:
thread.exit()
return
def clientTearDown(self):
self.done.set()
thread.exit()
def start_new_thread(function, args, kwargs={}):
"""Dummy implementation of thread.start_new_thread().
Compatibility is maintained by making sure that ``args`` is a
tuple and ``kwargs`` is a dictionary. If an exception is raised
and it is SystemExit (which can be done by thread.exit()) it is
caught and nothing is done; all other exceptions are printed out
by using traceback.print_exc().
If the executed function calls interrupt_main the KeyboardInterrupt will be
raised when the function returns.
"""
if type(args) != type(tuple()):
raise TypeError("2nd arg must be a tuple")
if type(kwargs) != type(dict()):
raise TypeError("3rd arg must be a dict")
global _main
_main = False
try:
function(*args, **kwargs)
except SystemExit:
pass
except:
_traceback.print_exc()
_main = True
global _interrupt
if _interrupt:
_interrupt = False
raise KeyboardInterrupt
def exit():
"""Dummy implementation of thread.exit()."""
raise SystemExit
def clientTearDown(self):
self.done.set()
thread.exit()
def start_new_thread(function, args, kwargs={}):
"""Dummy implementation of thread.start_new_thread().
Compatibility is maintained by making sure that ``args`` is a
tuple and ``kwargs`` is a dictionary. If an exception is raised
and it is SystemExit (which can be done by thread.exit()) it is
caught and nothing is done; all other exceptions are printed out
by using traceback.print_exc().
If the executed function calls interrupt_main the KeyboardInterrupt will be
raised when the function returns.
"""
if type(args) != type(tuple()):
raise TypeError("2nd arg must be a tuple")
if type(kwargs) != type(dict()):
raise TypeError("3rd arg must be a dict")
global _main
_main = False
try:
function(*args, **kwargs)
except SystemExit:
pass
except:
_traceback.print_exc()
_main = True
global _interrupt
if _interrupt:
_interrupt = False
raise KeyboardInterrupt
def exit():
"""Dummy implementation of thread.exit()."""
raise SystemExit
def start_new_thread(function, args, kwargs={}):
"""Dummy implementation of thread.start_new_thread().
Compatibility is maintained by making sure that ``args`` is a
tuple and ``kwargs`` is a dictionary. If an exception is raised
and it is SystemExit (which can be done by thread.exit()) it is
caught and nothing is done; all other exceptions are printed out
by using traceback.print_exc().
If the executed function calls interrupt_main the KeyboardInterrupt will be
raised when the function returns.
"""
if type(args) != type(tuple()):
raise TypeError("2nd arg must be a tuple")
if type(kwargs) != type(dict()):
raise TypeError("3rd arg must be a dict")
global _main
_main = False
try:
function(*args, **kwargs)
except SystemExit:
pass
except:
_traceback.print_exc()
_main = True
global _interrupt
if _interrupt:
_interrupt = False
raise KeyboardInterrupt
def exit():
"""Dummy implementation of thread.exit()."""
raise SystemExit
def runWithAccident():
print "***ready to test with event"
for (ip,name) in nodes:
accidentJoin(ip)
time.sleep(2)
print "****all nodes restarted"
#time.sleep(10)
#print "****wait for key"
#raw_input()
interval=event_interval
try:
if(options.recur):
simulateThread=threading.Thread(target=recurEventThread, args=(interval,test_time,))
else:
simulateThread=threading.Thread(target=simulateAccidentThread, args=(interval,test_time,))
#simulateThread=threading.Thread(target=simulateAccidentThread,args=(interval,test_time))
#simulateThread.start()
simulateThread.setDaemon(True)
simulateThread.start()
runTest()
GLOBAL_FLAG=False
print "****global flag:",GLOBAL_FLAG
simulateThread.join()
except KeyboardInterrupt:
exit(-1)
def runWithUser():
global GLOBAL_FLAG
global test_time
#reset all flag and let nodes work
for (ip,name) in nodes:
resetFlag(ip)
print "***ready to test with userdefine"
#time.sleep(10)
#print "****wait for key"
#raw_input()
interval=event_interval
try:
#if(1):
#simulateUserThread(interval,test_time)
#exit(0)
if(options.recur):
simulateThread=threading.Thread(target=recurUserThread, args=(interval,test_time,))
else:
simulateThread=threading.Thread(target=simulateUserThread, args=(interval,test_time,))
#simulateThread=threading.Thread(target=simulateAccidentThread,args=(interval,test_time))
#simulateThread.start()
simulateThread.setDaemon(True)
simulateThread.start()
runTest()
GLOBAL_FLAG=False
print "****global flag:",GLOBAL_FLAG
simulateThread.join()
except KeyboardInterrupt:
for (ip,name) in nodes:
resetFlag(ip)
exit(-1)
return
def handler(a,b):
global GLOBAL_FLAG
GLOBAL_FLAG=False
exit(0)
def run(self):
global options
sleepTime = self.sleepTime
slice = self.slice
# print "****time limit:",slice, slice*2
while (1):
startTime = self.startTime
stopTime = time.time()
totalTime = stopTime - startTime
# print "in timerThread, total time now %f" %(totalTime)
if (slice * 2 <= totalTime):
print "****Error in spark:too long time!"
thread.interrupt_main()
exit(0)
thread.exit()
if (slice <= totalTime):
print "****Timer:timeLock is locked!"
# reset all flag
# nodes=readConf()
# for (ip,name) in nodes:
# resetFlag(ip)
break
# print "****timer sleep"
# print "****pass time:", totalTime
time.sleep(sleepTime)
global eventThread
# eventThread.setRun(False)
print "****Timer:total time:%f" % (totalTime)
options.TIME_OUT_SIGNAL = True
print "****Timer:time over trigger:", options.TIME_OUT_SIGNAL
thread.interrupt_main()
def timer(startTime):
global TIME_OUT_SIGNAL
print ("in timerThread")
sleepTime=10
slice=options.timelimit
total=0
while (1):
stopTime=time.time()
totalTime=stopTime - startTime
# print "in timerThread, total time now %f" %(total)
if (slice * 2 <= totalTime):
print "****Error in spark:too long time!"
thread.interrupt_main()
thread.exit()
if (slice <= totalTime):
print "timer:timeLock is locked!"
break
time.sleep(sleepTime)
print "total time:%f" % (totalTime)
TIME_OUT_SIGNAL=True
# on_signal_usr1(0,0)
# os.kill(pid,signal.SIGUSR1)