本文整理汇总了Python中faulthandler.dump_traceback方法的典型用法代码示例。如果您正苦于以下问题:Python faulthandler.dump_traceback方法的具体用法?Python faulthandler.dump_traceback怎么用?Python faulthandler.dump_traceback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类faulthandler
的用法示例。
在下文中一共展示了faulthandler.dump_traceback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _logInfoWidget
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import dump_traceback [as 别名]
def _logInfoWidget(self):
group = QGroupBox()
group.setTitle(catalog.i18nc("@title:groupbox", "Logs"))
layout = QVBoxLayout()
text_area = QTextEdit()
tmp_file_fd, tmp_file_path = tempfile.mkstemp(prefix = "cura-crash", text = True)
os.close(tmp_file_fd)
with open(tmp_file_path, "w", encoding = "utf-8") as f:
faulthandler.dump_traceback(f, all_threads=True)
with open(tmp_file_path, "r", encoding = "utf-8") as f:
logdata = f.read()
text_area.setText(logdata)
text_area.setReadOnly(True)
layout.addWidget(text_area)
group.setLayout(layout)
self.data["log"] = logdata
return group
示例2: main
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import dump_traceback [as 别名]
def main(argv):
del argv
logging.info('Starting RL training.')
gin_configs = FLAGS.config or []
gin.parse_config_files_and_bindings(FLAGS.config_file, gin_configs)
logging.info('Gin cofig:')
logging.info(gin_configs)
train_rl(
output_dir=FLAGS.output_dir,
train_batch_size=FLAGS.train_batch_size,
eval_batch_size=FLAGS.eval_batch_size,
trajectory_dump_dir=(FLAGS.trajectory_dump_dir or None),
)
# TODO(afrozm): This is for debugging.
logging.info('Dumping stack traces of all stacks.')
faulthandler.dump_traceback(all_threads=True)
logging.info('Training is done, should exit.')
示例3: test_truncate
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import dump_traceback [as 别名]
def test_truncate(self):
maxlen = 500
func_name = 'x' * (maxlen + 50)
truncated = 'x' * maxlen + '...'
code = """
import faulthandler
def {func_name}():
faulthandler.dump_traceback(all_threads=False)
{func_name}()
"""
code = code.format(
func_name=func_name,
)
expected = [
'Stack (most recent call first):',
' File "<string>", line 4 in %s' % truncated,
' File "<string>", line 6 in <module>'
]
trace, exitcode = self.get_output(code)
self.assertEqual(trace, expected)
self.assertEqual(exitcode, 0)
示例4: _fail_on_deadlock
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import dump_traceback [as 别名]
def _fail_on_deadlock(self, executor):
# If we did not recover before TIMEOUT seconds, consider that the
# executor is in a deadlock state and forcefully clean all its
# composants.
import faulthandler
from tempfile import TemporaryFile
with TemporaryFile(mode="w+") as f:
faulthandler.dump_traceback(file=f)
f.seek(0)
tb = f.read()
for p in executor._processes.values():
p.terminate()
# This should be safe to call executor.shutdown here as all possible
# deadlocks should have been broken.
executor.shutdown(wait=True)
print(f"\nTraceback:\n {tb}", file=sys.__stderr__)
self.fail(f"Executor deadlock:\n\n{tb}")
示例5: dump_traceback
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import dump_traceback [as 别名]
def dump_traceback():
frames = sys._current_frames()
th_traces = []
for th_ident, frame in frames.items():
trace_entries = traceback.format_stack(frame)
# Comply with faulthandler output
context_str = 'Thread'
if th_ident == thread.get_ident():
context_str = 'Current thread'
trace_header = '%s 0x%x (most recent call first):' % (context_str, th_ident)
trace_entries.append(trace_header)
trace_entries.reverse()
pretty_trace_entries = [s.split('\n')[0] for s in trace_entries]
th_traces.append('\n'.join(pretty_trace_entries))
print('\n\n'.join(th_traces), file=sys.stderr)
示例6: dump_stacktraces
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import dump_traceback [as 别名]
def dump_stacktraces(sig, frame):
dump_traceback()
示例7: start_threads
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import dump_traceback [as 别名]
def start_threads(threads, unlock=None):
threads = list(threads)
started = []
try:
try:
for t in threads:
t.start()
started.append(t)
except:
if verbose:
print("Can't start %d threads, only %d threads started" %
(len(threads), len(started)))
raise
yield
finally:
try:
if unlock:
unlock()
endtime = starttime = time.time()
for timeout in range(1, 16):
endtime += 60
for t in started:
t.join(max(endtime - time.time(), 0.01))
started = [t for t in started if t.isAlive()]
if not started:
break
if verbose:
print('Unable to join %d threads during a period of '
'%d minutes' % (len(started), timeout))
finally:
started = [t for t in started if t.isAlive()]
if started:
faulthandler.dump_traceback(sys.stdout)
raise AssertionError('Unable to join %d threads' % len(started))
示例8: test_stderr_None
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import dump_traceback [as 别名]
def test_stderr_None(self):
# Issue #21497: provide an helpful error if sys.stderr is None,
# instead of just an attribute error: "None has no attribute fileno".
with self.check_stderr_none():
faulthandler.enable()
with self.check_stderr_none():
faulthandler.dump_traceback()
if hasattr(faulthandler, 'dump_traceback_later'):
with self.check_stderr_none():
faulthandler.dump_traceback_later(1e-3)
if hasattr(faulthandler, "register"):
with self.check_stderr_none():
faulthandler.register(signal.SIGUSR1)
示例9: check_dump_traceback
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import dump_traceback [as 别名]
def check_dump_traceback(self, filename):
"""
Explicitly call dump_traceback() function and check its output.
Raise an error if the output doesn't match the expected format.
"""
code = """
import faulthandler
def funcB():
if {has_filename}:
with open({filename}, "wb") as fp:
faulthandler.dump_traceback(fp, all_threads=False)
else:
faulthandler.dump_traceback(all_threads=False)
def funcA():
funcB()
funcA()
"""
code = code.format(
filename=repr(filename),
has_filename=bool(filename),
)
if filename:
lineno = 6
else:
lineno = 8
expected = [
'Stack (most recent call first):',
' File "<string>", line %s in funcB' % lineno,
' File "<string>", line 11 in funcA',
' File "<string>", line 13 in <module>'
]
trace, exitcode = self.get_output(code, filename)
self.assertEqual(trace, expected)
self.assertEqual(exitcode, 0)
示例10: _check_executor_started
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import dump_traceback [as 别名]
def _check_executor_started(executor):
# Submit a small job to make sure that the pool is an working state
res = executor.submit(id, None)
try:
res.result(timeout=TIMEOUT)
except TimeoutError:
print('\n' * 3, res.done(), executor._call_queue.empty(),
executor._result_queue.empty())
print(executor._processes)
print(threading.enumerate())
from faulthandler import dump_traceback
dump_traceback()
executor.submit(dump_traceback).result(TIMEOUT)
raise RuntimeError("Executor took too long to run basic task.")
示例11: test_stderr_None
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import dump_traceback [as 别名]
def test_stderr_None(self):
# Issue #21497: provide a helpful error if sys.stderr is None,
# instead of just an attribute error: "None has no attribute fileno".
with self.check_stderr_none():
faulthandler.enable()
with self.check_stderr_none():
faulthandler.dump_traceback()
if hasattr(faulthandler, 'dump_traceback_later'):
with self.check_stderr_none():
faulthandler.dump_traceback_later(1e-3)
if hasattr(faulthandler, "register"):
with self.check_stderr_none():
faulthandler.register(signal.SIGUSR1)
示例12: _asynciostacks
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import dump_traceback [as 别名]
def _asynciostacks(*args, **kwargs): # pragma: no cover
'''
A signal handler used to print asyncio task stacks and thread stacks.
'''
print(80 * '*')
print('Asyncio tasks stacks:')
tasks = asyncio.all_tasks(_glob_loop)
for task in tasks:
task.print_stack()
print(80 * '*')
print('Faulthandler stack frames per thread:')
faulthandler.dump_traceback()
print(80 * '*')
示例13: _threadstacks
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import dump_traceback [as 别名]
def _threadstacks(*args, **kwargs): # pragma: no cover
'''
A signal handler used to print thread stacks.
'''
print(80 * '*')
print('Faulthandler stack frames per thread:')
faulthandler.dump_traceback()
print(80 * '*')
示例14: render_GET
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import dump_traceback [as 别名]
def render_GET(self, request):
logger.info("Handling thread dump request")
try:
with open('/var/log/anchore/pid_{}_thread_dump-{}'.format(os.getpid(), datetime.datetime.now().isoformat()), 'w') as dest:
faulthandler.dump_traceback(dest, all_threads=True)
except:
logger.exception('Error dumping thread frames')
return b'Failed'
return b'Sucess'
示例15: check_dump_traceback
# 需要导入模块: import faulthandler [as 别名]
# 或者: from faulthandler import dump_traceback [as 别名]
def check_dump_traceback(self, *, filename=None, fd=None):
"""
Explicitly call dump_traceback() function and check its output.
Raise an error if the output doesn't match the expected format.
"""
code = """
import faulthandler
filename = {filename!r}
fd = {fd}
def funcB():
if filename:
with open(filename, "wb") as fp:
faulthandler.dump_traceback(fp, all_threads=False)
elif fd is not None:
faulthandler.dump_traceback(fd,
all_threads=False)
else:
faulthandler.dump_traceback(all_threads=False)
def funcA():
funcB()
funcA()
"""
code = code.format(
filename=filename,
fd=fd,
)
if filename:
lineno = 9
elif fd is not None:
lineno = 12
else:
lineno = 14
expected = [
'Stack (most recent call first):',
' File "<string>", line %s in funcB' % lineno,
' File "<string>", line 17 in funcA',
' File "<string>", line 19 in <module>'
]
trace, exitcode = self.get_output(code, filename, fd)
self.assertEqual(trace, expected)
self.assertEqual(exitcode, 0)