本文整理汇总了Python中traceback.print_exception方法的典型用法代码示例。如果您正苦于以下问题:Python traceback.print_exception方法的具体用法?Python traceback.print_exception怎么用?Python traceback.print_exception使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类traceback
的用法示例。
在下文中一共展示了traceback.print_exception方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: formatException
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import print_exception [as 别名]
def formatException(self, ei):
"""
Format and return the specified exception information as a string.
This default implementation just uses
traceback.print_exception()
"""
sio = io.StringIO()
tb = ei[2]
# See issues #9427, #1553375. Commented out for now.
#if getattr(self, 'fullstack', False):
# traceback.print_stack(tb.tb_frame.f_back, file=sio)
traceback.print_exception(ei[0], ei[1], tb, None, sio)
s = sio.getvalue()
sio.close()
if s[-1:] == "\n":
s = s[:-1]
return s
示例2: handleError
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import print_exception [as 别名]
def handleError(self, record):
"""
Handle errors which occur during an emit() call.
This method should be called from handlers when an exception is
encountered during an emit() call. If raiseExceptions is false,
exceptions get silently ignored. This is what is mostly wanted
for a logging system - most users will not care about errors in
the logging system, they are more interested in application errors.
You could, however, replace this with a custom handler if you wish.
The record which was being processed is passed in to this method.
"""
if raiseExceptions and sys.stderr: # see issue 13807
ei = sys.exc_info()
try:
traceback.print_exception(ei[0], ei[1], ei[2],
None, sys.stderr)
sys.stderr.write('Logged from file %s, line %s\n' % (
record.filename, record.lineno))
except IOError: #pragma: no cover
pass # see issue 5971
finally:
del ei
示例3: emit
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import print_exception [as 别名]
def emit(self, record):
"""
Emit a record.
If a formatter is specified, it is used to format the record.
The record is then written to the stream with a trailing newline. If
exception information is present, it is formatted using
traceback.print_exception and appended to the stream. If the stream
has an 'encoding' attribute, it is used to determine how to do the
output to the stream.
"""
try:
msg = self.format(record)
stream = self.stream
stream.write(msg)
stream.write(self.terminator)
self.flush()
except (KeyboardInterrupt, SystemExit): #pragma: no cover
raise
except:
self.handleError(record)
示例4: _getexcepthook
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import print_exception [as 别名]
def _getexcepthook():
"Return a function that can be used as except hook for uncaught exceptions."
if not sys.argv[0]:
# We are in interactive mode and don't want to terminate
return sys.excepthook
# else create a function that terminates all spawned processes and this
# in case of an uncaught exception
exit = _getexitfunction()
def excepthook(exctype, excvalue, exctraceback):
import traceback
sys.stderr.write(
"An uncaught exception occured. Terminating pygrametl.\n")
traceback.print_exception(exctype, excvalue, exctraceback)
exit()
return excepthook
# Stuff for @splitpoint
示例5: on_command_error
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import print_exception [as 别名]
def on_command_error(self, context, exception):
"""|coro|
The default command error handler provided by the bot.
By default this prints to :data:`sys.stderr` however it could be
overridden to have a different implementation.
This only fires if you do not specify any listeners for command error.
"""
if self.extra_events.get('on_command_error', None):
return
if hasattr(context.command, 'on_error'):
return
cog = context.cog
if cog:
if Cog._get_overridden_method(cog.cog_command_error) is not None:
return
print('Ignoring exception in command {}:'.format(context.command), file=sys.stderr)
traceback.print_exception(type(exception), exception, exception.__traceback__, file=sys.stderr)
# global check registration
示例6: exception_traceback
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import print_exception [as 别名]
def exception_traceback(exc_info=None):
"""
Return a string containing a traceback message for the given
exc_info tuple (as returned by sys.exc_info()).
from setuptools.tests.doctest
"""
if not exc_info:
exc_info = sys.exc_info()
# Get a traceback message.
excout = StringIO()
exc_type, exc_val, exc_tb = exc_info
traceback.print_exception(exc_type, exc_val, exc_tb, file=excout)
return excout.getvalue()
示例7: main
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import print_exception [as 别名]
def main(argv=None):
if argv is None:
argv = sys.argv[1:]
try:
in_filename = argv[0]
except IndexError:
print(globals()['__doc__'], file=sys.stderr)
return os.EX_USAGE
try:
report_segy(in_filename)
except (FileNotFoundError, IsADirectoryError) as e:
print(e, file=sys.stderr)
return os.EX_NOINPUT
except PermissionError as e:
print(e, file=sys.stderr)
return os.EX_NOPERM
except Exception as e:
traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr)
return os.EX_SOFTWARE
return os.EX_OK
示例8: main
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import print_exception [as 别名]
def main(argv=None):
if argv is None:
argv = sys.argv[1:]
try:
scale_factor = float(argv[0])
in_filename = argv[1]
out_filename = argv[2]
except (ValueError, IndexError):
print(globals()['__doc__'], file=sys.stderr)
return os.EX_USAGE
try:
transform(scale_factor, in_filename, out_filename)
except (FileNotFoundError, IsADirectoryError) as e:
print(e, file=sys.stderr)
return os.EX_NOINPUT
except PermissionError as e:
print(e, file=sys.stderr)
return os.EX_NOPERM
except Exception as e:
traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr)
return os.EX_SOFTWARE
return os.EX_OK
示例9: main
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import print_exception [as 别名]
def main(argv=None):
if argv is None:
argv = sys.argv[1:]
try:
in_filename = argv[0]
out_filename = argv[1]
except IndexError:
print(globals()['__doc__'], file=sys.stderr)
return os.EX_USAGE
try:
load_save(in_filename, out_filename)
except (FileNotFoundError, IsADirectoryError) as e:
print(e, file=sys.stderr)
return os.EX_NOINPUT
except PermissionError as e:
print(e, file=sys.stderr)
return os.EX_NOPERM
except Exception as e:
traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr)
return os.EX_SOFTWARE
return os.EX_OK
示例10: main
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import print_exception [as 别名]
def main(argv=None):
if argv is None:
argv = sys.argv[1:]
try:
in_filename = argv[0]
except IndexError:
print(globals()['__doc__'], file=sys.stderr)
return os.EX_USAGE
try:
read_traces(in_filename)
except (FileNotFoundError, IsADirectoryError) as e:
print(e, file=sys.stderr)
return os.EX_NOINPUT
except PermissionError as e:
print(e, file=sys.stderr)
return os.EX_NOPERM
except Exception as e:
traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr)
return os.EX_SOFTWARE
return os.EX_OK
示例11: _setup_logging
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import print_exception [as 别名]
def _setup_logging(self, config):
log_config_file = config[u'log'][u'config_file']
self._logger.info(u'Logging configuration file: ' + log_config_file)
try:
logging.config.fileConfig(log_config_file)
except Exception:
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_traceback, limit=2, file=sys.stderr)
raise PanoptesConfigurationError(
u'Could not instantiate logger with logging configuration provided in file "%s": (%s) %s' % (
log_config_file, exc_type, exc_value))
# Create a filter to rate limit logs so that a misconfiguration or failure does not make the disk I/O go
# beserk or fill up the disk space. We do this in code instead if configuration for two reasons:
# - It enforces a filter on every handler, so no chance of messing them up in configuration
# - We use fileConfig (nof dictConfig) to setup our logging and fileConfig does not support filter configuration
throttle = RateLimitingFilter(rate=config[u'log'][u'rate'], per=config[u'log'][u'per'],
burst=config[u'log'][u'burst'])
# Apply the filter to all handlers. Note that this would be a shared filter across ALL logs generated by this
# process and thus the rate/burst should be set appropriately high
for handler in logging._handlerList:
# _handlerList is a list of weakrefs, so the object returned has to be dereferenced
handler().addFilter(throttle)
示例12: handleError
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import print_exception [as 别名]
def handleError(self, record):
"""
Handle errors which occur during an emit() call.
This method should be called from handlers when an exception is
encountered during an emit() call. If raiseExceptions is false,
exceptions get silently ignored. This is what is mostly wanted
for a logging system - most users will not care about errors in
the logging system, they are more interested in application errors.
You could, however, replace this with a custom handler if you wish.
The record which was being processed is passed in to this method.
"""
if raiseExceptions:
ei = sys.exc_info()
try:
traceback.print_exception(ei[0], ei[1], ei[2],
None, sys.stderr)
sys.stderr.write('Logged from file %s, line %s\n' % (
record.filename, record.lineno))
except IOError:
pass # see issue 5971
finally:
del ei
示例13: handleError
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import print_exception [as 别名]
def handleError(self, record):
"""
Handle errors which occur during an emit() call.
This method should be called from handlers when an exception is
encountered during an emit() call. If raiseExceptions is false,
exceptions get silently ignored. This is what is mostly wanted
for a logging system - most users will not care about errors in
the logging system, they are more interested in application errors.
You could, however, replace this with a custom handler if you wish.
The record which was being processed is passed in to this method.
"""
if raiseExceptions and sys.stderr: # see issue 13807
ei = sys.exc_info()
try:
traceback.print_exception(ei[0], ei[1], ei[2],
None, sys.stderr)
sys.stderr.write('Logged from file %s, line %s\n' % (
record.filename, record.lineno))
except IOError:
pass # see issue 5971
finally:
del ei
示例14: _Invoke_
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import print_exception [as 别名]
def _Invoke_(self, dispid, lcid, wFlags, args):
print "In Invoke with", dispid, lcid, wFlags, args, "with object",self.policy._obj_
try:
rc = win32com.server.policy.DispatcherBase._Invoke_(self, dispid, lcid, wFlags, args)
# print "Invoke of", dispid, "returning", rc
return rc
except Exception:
t, v, tb = sys.exc_info()
tb = None # A cycle
scode = v.scode
try:
desc = " (" + str(v.description) + ")"
except AttributeError:
desc = ""
print "*** Invoke of %s raised COM exception 0x%x%s" % (dispid, scode, desc)
except:
print "*** Invoke of %s failed:" % dispid
typ, val, tb = sys.exc_info()
import traceback
traceback.print_exception(typ, val, tb)
raise
示例15: InjectString
# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import print_exception [as 别名]
def InjectString(self, codestring, wait_for_completion=True):
"""Try to inject python code into current thread.
Args:
codestring: Python snippet to execute in inferior. (may contain newlines)
wait_for_completion: Block until execution of snippet has completed.
"""
if self.inferior.is_running and self.inferior.gdb.IsAttached():
try:
self.inferior.gdb.InjectString(
self.inferior.position,
codestring,
wait_for_completion=wait_for_completion)
except RuntimeError:
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_traceback)
else:
logging.error('Not attached to any process.')