本文整理汇总了Python中_thread.exit方法的典型用法代码示例。如果您正苦于以下问题:Python _thread.exit方法的具体用法?Python _thread.exit怎么用?Python _thread.exit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_thread
的用法示例。
在下文中一共展示了_thread.exit方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gpu_status
# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import exit [as 别名]
def gpu_status(self,av_type_list):
for t in av_type_list:
cmd='nvidia-smi -q --display='+t
#print('\nCMD:',cmd,'\n')
r=os.popen(cmd)
info=r.readlines()
r.close()
content = " ".join(info)
#print('\ncontent:',content,'\n')
index=content.find('Attached GPUs')
s=content[index:].replace(' ','').rstrip('\n')
self.t_send(s, toUserName='filehelper')
time.sleep(.5)
#th.exit()
#==============================================================================
#
#==============================================================================
示例2: run_task
# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import exit [as 别名]
def run_task(self, task):
for try_number in range(self.times_to_retry + 1):
self.__register_start(task)
task.run()
self.__register_exit(task)
if task.exit_code == 0:
break
if try_number < self.times_to_retry:
execution_number = self.__get_next_execution_number(task.test_id)
# We need create a new Task instance. Each task represents a single test
# execution, with its own runtime, exit code and log file.
task = self.task_factory(task.test_binary, task.test_name,
task.test_command, execution_number,
task.last_execution_time, task.output_dir)
with self.lock:
if task.exit_code != 0:
self.global_exit_code = task.exit_code
示例3: start_new_thread
# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import exit [as 别名]
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:
import traceback
traceback.print_exc()
_main = True
global _interrupt
if _interrupt:
_interrupt = False
raise KeyboardInterrupt
示例4: exit
# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import exit [as 别名]
def exit():
"""Dummy implementation of _thread.exit()."""
raise SystemExit
示例5: run
# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import exit [as 别名]
def run(self):
begin = time.time()
with open(self.log_file, 'w') as log:
task = subprocess.Popen(self.test_command, stdout=log, stderr=log)
try:
self.exit_code = sigint_handler.wait(task)
except sigint_handler.ProcessWasInterrupted:
thread.exit()
self.runtime_ms = int(1000 * (time.time() - begin))
self.last_execution_time = None if self.exit_code else self.runtime_ms
示例6: log_exit
# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import exit [as 别名]
def log_exit(self, task):
with self.stdout_lock:
self.finished_tasks += 1
self.out.transient_line("[%d/%d] %s (%d ms)"
% (self.finished_tasks, self.total_tasks,
task.test_name, task.runtime_ms))
if task.exit_code != 0:
with open(task.log_file) as f:
for line in f.readlines():
self.out.permanent_line(line.rstrip())
self.out.permanent_line(
"[%d/%d] %s returned/aborted with exit code %d (%d ms)"
% (self.finished_tasks, self.total_tasks, task.test_name,
task.exit_code, task.runtime_ms))
if self.output_dir is None:
# Try to remove the file 100 times (sleeping for 0.1 second in between).
# This is a workaround for a process handle seemingly holding on to the
# file for too long inside os.subprocess. This workaround is in place
# until we figure out a minimal repro to report upstream (or a better
# suspect) to prevent os.remove exceptions.
num_tries = 100
for i in range(num_tries):
try:
os.remove(task.log_file)
except OSError as e:
if e.errno is not errno.ENOENT:
if i is num_tries - 1:
self.out.permanent_line('Could not remove temporary log file: ' + str(e))
else:
time.sleep(0.1)
continue
break
示例7: _clientTearDown
# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import exit [as 别名]
def _clientTearDown(self):
self.done.set()
try:
if hasattr(self, 'clientTearDown'):
self.clientTearDown()
except BaseException as e:
self.queue.put(e)
finally:
thread.exit()
示例8: clientTearDown
# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import exit [as 别名]
def clientTearDown(self):
self.done.set()
thread.exit()
示例9: start
# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import exit [as 别名]
def start(self, run):
thread.start_new_thread(run)
def stop(self):
thread.exit()