本文整理汇总了Python中traceback.format_stack方法的典型用法代码示例。如果您正苦于以下问题:Python traceback.format_stack方法的具体用法?Python traceback.format_stack怎么用?Python traceback.format_stack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类traceback
的用法示例。
在下文中一共展示了traceback.format_stack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: log
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_stack [as 别名]
def log(msg, msgx='', level=logging.INFO, need_tb=False):
"""
Logging in UCC Config Module.
:param msg: message content
:param msgx: detail info.
:param level: logging level
:param need_tb: if need logging traceback
:return:
"""
global LOGGING_STOPPED
if LOGGING_STOPPED:
return
msgx = ' - ' + msgx if msgx else ''
content = 'UCC Config Module: %s%s' % (msg, msgx)
if need_tb:
stack = ''.join(traceback.format_stack())
content = '%s\r\n%s' % (content, stack)
stulog.logger.log(level, content, exc_info=1)
示例2: error
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_stack [as 别名]
def error(message: str, *, stack: str = None, replace: bool = False) -> None:
"""Display an error message.
Args:
message: The message to show.
stack: The stack trace to show (if any).
replace: Replace existing messages which are still being shown.
"""
if stack is None:
stack = ''.join(traceback.format_stack())
typ = 'error'
else:
typ = 'error (from exception)'
_log_stack(typ, stack)
log.message.error(message)
global_bridge.show(usertypes.MessageLevel.error, message, replace)
示例3: _do_get
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_stack [as 别名]
def _do_get(self):
if self._checked_out:
if self._checkout_traceback:
suffix = ' at:\n%s' % ''.join(
chop_traceback(self._checkout_traceback))
else:
suffix = ''
raise AssertionError("connection is already checked out" + suffix)
if not self._conn:
self._conn = self._create_connection()
self._checked_out = True
if self._store_traceback:
self._checkout_traceback = traceback.format_stack()
return self._conn
示例4: thread_stacktraces
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_stack [as 别名]
def thread_stacktraces():
"""
Provides a dump of the stacktrace information for all active threads.
:returns: **dict** that maps thread names to their stacktrace
"""
stacktraces = {}
for thread in threading.enumerate():
frame = sys._current_frames().get(thread.ident, None)
if frame:
stacktraces[thread.name] = ''.join(traceback.format_stack(frame))
else:
stacktraces[thread.name] = 'No traceback available'
return stacktraces
示例5: tryLock
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_stack [as 别名]
def tryLock(self, timeout=None, id=None):
if timeout is None:
locked = QtCore.QMutex.tryLock(self)
else:
locked = QtCore.QMutex.tryLock(self, timeout)
if self.debug and locked:
self.l.lock()
try:
if id is None:
self.tb.append(''.join(traceback.format_stack()[:-1]))
else:
self.tb.append(" " + str(id))
#print 'trylock', self, len(self.tb)
finally:
self.l.unlock()
return locked
示例6: _startRunCallbacks
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_stack [as 别名]
def _startRunCallbacks(self, result):
if self.called:
if self._suppressAlreadyCalled:
self._suppressAlreadyCalled = False
return
if self.debug:
if self._debugInfo is None:
self._debugInfo = DebugInfo()
extra = "\n" + self._debugInfo._getDebugTracebacks()
raise AlreadyCalledError(extra)
raise AlreadyCalledError
if self.debug:
if self._debugInfo is None:
self._debugInfo = DebugInfo()
self._debugInfo.invoker = traceback.format_stack()[:-2]
self.called = True
self.result = result
self._runCallbacks()
示例7: inspect_threads
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_stack [as 别名]
def inspect_threads(thread_names=[]):
"""inspect_threads() -> {thread_name: {"locals": {}, "stack": ""}} : return threads' locals and stack"""
import threading
import sys
import traceback
pylane_thread_name = "pylane-shell-thread"
stacks = {}
frames = sys._current_frames()
threads = threading.enumerate()
for thread in threads:
if thread.name == pylane_thread_name:
continue
if thread_names and thread.name not in thread_names:
continue
frame = frames.get(thread.ident)
stack = ''.join(traceback.format_stack(frame)) if frame else ''
stacks[thread.name] = {
"locals": frame.f_locals,
"stack": stack
}
return stacks
示例8: format_error
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_stack [as 别名]
def format_error(e):
# errback automatically wraps everything in a Twisted Failure
if isinstance(e, failure.Failure):
e = e.value
if isinstance(e, str):
err_string = e
elif six.PY2:
err_string = traceback.format_exc(e).rstrip()
else:
err_string = ''.join(traceback.format_exception(type(e), e, e.__traceback__)).rstrip()
if err_string == 'None':
# Reasonable heuristic for exceptions that were created by hand
last = traceback.format_stack()[-2]
err_string = '{}\n {}'.format(e, last)
# Quick and dirty hack for now.
err_string = err_string.replace('Connection to the other side was lost in a non-clean fashion', 'Connection to the other side was lost in a non-clean fashion (HINT: this generally actually means we got a connection refused error. Check that the remote is actually running.)')
return error.Error(err_string)
示例9: retain_error
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_stack [as 别名]
def retain_error(self, error, frame=None):
"""
Adds details of an error to the report.
:param error: The error exception to add to the report.
"""
if frame is None:
stack = traceback.format_exc()
self.labels.add("@iopipe/error")
else:
stack = "\n".join(traceback.format_stack(frame))
self.labels.add("@iopipe/timeout")
details = {
"name": type(error).__name__,
"message": "{}".format(error),
"stack": stack,
}
self.report["errors"] = details
示例10: debug_signal
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_stack [as 别名]
def debug_signal(signum, frame):
import sys, traceback
for thread_id, stack in sys._current_frames().iteritems():
print('Thread id: %s\n%s' % (thread_id, ''.join(traceback.format_stack(stack))))
示例11: _assert
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_stack [as 别名]
def _assert(condition):
if not condition:
sys.stderr.write(''.join(traceback.format_stack()[:-1]))
comm.Abort()
示例12: log_expect_failure
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_stack [as 别名]
def log_expect_failure(self, expected_pattern):
self.write_result("\n\n*** Did not find expected pattern {}\n\n".format(expected_pattern))
# Generate a call stack in rift_expect.log for easier debugging
# But pytest call stacks are very deep, so only show the "interesting" lines
for line in traceback.format_stack():
if "tests/" in line:
self.write_result(line.strip())
self.write_result("\n")
示例13: expect_failure
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_stack [as 别名]
def expect_failure(self, msg):
self._results_file.write(msg + "\n\n")
# Generate a call stack in rift_expect.log for easier debugging
# But pytest call stacks are very deep, so only show the "interesting" lines
for line in traceback.format_stack():
if "tests/" in line:
self._results_file.write(line.strip())
self._results_file.write("\n")
assert False, msg + " (see log_expect.log for details)"
示例14: log_expect_failure
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_stack [as 别名]
def log_expect_failure(self):
self.write_result("\n\n*** Did not find expected pattern\n\n")
# Generate a call stack in the log file for easier debugging
for line in traceback.format_stack():
self.write_result(line.strip())
self.write_result("\n")
示例15: log_stack
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_stack [as 别名]
def log_stack(self, signal, frame):
"""Signal handler to log the stack trace of the current thread.
For use with `set_blocking_signal_threshold`.
"""
gen_log.warning('IOLoop blocked for %f seconds in\n%s',
self._blocking_signal_threshold,
''.join(traceback.format_stack(frame)))