本文整理汇总了Python中traceback._format_exc函数的典型用法代码示例。如果您正苦于以下问题:Python _format_exc函数的具体用法?Python _format_exc怎么用?Python _format_exc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_format_exc函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unexpected_json_error_handler
def unexpected_json_error_handler():
"""request.error_response"""
(typ, value, tb) = _exc_info()
if typ:
debug = False
if hasattr(cherrypy.request, 'params'):
params = cherrypy.request.params
debug = 'debug' in params and params['debug']
response = cherrypy.response
response.headers['Content-Type'] = 'application/json'
response.headers.pop('Content-Length', None)
content = {}
if isinstance(value, ExtendedHTTPError):
content.update({'errors': value.errors})
if isinstance(typ, cherrypy.HTTPError):
cherrypy._cperror.clean_headers(value.code)
response.status = value.status
content.update({'code': value.code, 'reason': value.reason,
'message': value._message})
elif isinstance(typ, (TypeError, ValueError, KeyError)):
cherrypy._cperror.clean_headers(400)
response.status = 400
reason, default_message = _httputil.response_codes[400]
content = {'code': 400, 'reason': reason,
'message': value.message or default_message}
if cherrypy.serving.request.show_tracebacks or debug:
tb = _format_exc()
content['traceback'] = tb
response.body = json.dumps(content).encode('utf-8')
示例2: __bootstrap_inner
def __bootstrap_inner(self):
try:
self._set_ident()
self.__started.set()
with _active_limbo_lock:
_active[self.__ident] = self
del _limbo[self]
self._note("%s.__bootstrap(): thread started", self)
if _trace_hook:
self._note("%s.__bootstrap(): registering trace hook", self)
_sys.settrace(_trace_hook)
if _profile_hook:
self._note("%s.__bootstrap(): registering profile hook", self)
_sys.setprofile(_profile_hook)
try:
self.run()
except SystemExit:
self._note("%s.__bootstrap(): raised SystemExit", self)
except:
self._note("%s.__bootstrap(): unhandled exception", self)
if _sys:
_sys.stderr.write("Exception in thread %s:\n%s\n" % (self.name, _format_exc()))
else:
exc_type, exc_value, exc_tb = self.__exc_info()
try:
print >> self.__stderr, "Exception in thread " + self.name + " (most likely raised during interpreter shutdown):"
print >> self.__stderr, "Traceback (most recent call last):"
while exc_tb:
print >> self.__stderr, ' File "%s", line %s, in %s' % (
exc_tb.tb_frame.f_code.co_filename,
exc_tb.tb_lineno,
exc_tb.tb_frame.f_code.co_name,
)
exc_tb = exc_tb.tb_next
print >> self.__stderr, "%s: %s" % (exc_type, exc_value)
finally:
del exc_type
del exc_value
del exc_tb
else:
self._note("%s.__bootstrap(): normal return", self)
finally:
self.__exc_clear()
finally:
with _active_limbo_lock:
self.__stop()
try:
del _active[_get_ident()]
except:
pass
示例3: handler
def handler(exc=None, passthru=True):
if exc is None:
exc = sys.exc_info()
TEXT = _format_exc(exc)
try:
_thread = _currentThread()
TEXT = ("Exception in thread %s:\n" % _thread.name) + TEXT
except: pass
CMD = len(sys.argv) > 1 and sys.argv[1].endswith('.py') and sys.argv[1] or sys.argv[0]
SUBJECT = CMD+': '+str(exc[1]).replace('\r','').replace('\n','')
HEADERS = 'From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n' % (EMAIL_FROM, EMAIL_TO, SUBJECT)
_SMTP('localhost').sendmail(EMAIL_FROM, [EMAIL_TO], HEADERS+TEXT)
if passthru:
sys.__excepthook__(*exc)
return TEXT
示例4: _bootstrap_inner
def _bootstrap_inner(self):
try:
self._set_ident()
self._started.set()
with _active_limbo_lock:
_active[self._ident] = self
del _limbo[self]
if _trace_hook:
_sys.settrace(_trace_hook)
if _profile_hook:
_sys.setprofile(_profile_hook)
try:
self.run()
except SystemExit:
pass
except:
if _sys:
_sys.stderr.write('Exception in thread %s:\n%s\n' % (self.name, _format_exc()))
else:
(exc_type, exc_value, exc_tb) = self._exc_info()
try:
print('Exception in thread ' + self.name + ' (most likely raised during interpreter shutdown):', file=self._stderr)
print('Traceback (most recent call last):', file=self._stderr)
while exc_tb:
print(' File "%s", line %s, in %s' % (exc_tb.tb_frame.f_code.co_filename, exc_tb.tb_lineno, exc_tb.tb_frame.f_code.co_name), file=self._stderr)
exc_tb = exc_tb.tb_next
print('%s: %s' % (exc_type, exc_value), file=self._stderr)
finally:
del exc_type
del exc_value
del exc_tb
finally:
pass
finally:
with _active_limbo_lock:
self._stop()
try:
del _active[get_ident()]
except:
pass
示例5: __bootstrap_inner
def __bootstrap_inner(self):
try:
self._set_ident()
self.__started.set()
with _active_limbo_lock:
_active[self.__ident] = self
del _limbo[self]
if __debug__:
self._note("%s.__bootstrap(): thread started", self)
if _trace_hook:
self._note("%s.__bootstrap(): registering trace hook", self)
_sys.settrace(_trace_hook)
if _profile_hook:
self._note("%s.__bootstrap(): registering profile hook", self)
_sys.setprofile(_profile_hook)
try:
self.run()
except SystemExit:
if __debug__:
self._note("%s.__bootstrap(): raised SystemExit", self)
except:
if __debug__:
self._note("%s.__bootstrap(): unhandled exception", self)
# If sys.stderr is no more (most likely from interpreter
# shutdown) use self.__stderr. Otherwise still use sys (as in
# _sys) in case sys.stderr was redefined since the creation of
# self.
if _sys:
_sys.stderr.write("Exception in thread %s:\n%s\n" % (self.name, _format_exc()))
else:
# Do the best job possible w/o a huge amt. of code to
# approximate a traceback (code ideas from
# Lib/traceback.py)
exc_type, exc_value, exc_tb = self.__exc_info()
try:
print >> self.__stderr, (
"Exception in thread " + self.name + " (most likely raised during interpreter shutdown):"
)
print >> self.__stderr, ("Traceback (most recent call last):")
while exc_tb:
print >> self.__stderr, (
' File "%s", line %s, in %s'
% (exc_tb.tb_frame.f_code.co_filename, exc_tb.tb_lineno, exc_tb.tb_frame.f_code.co_name)
)
exc_tb = exc_tb.tb_next
print >> self.__stderr, ("%s: %s" % (exc_type, exc_value))
# Make sure that exc_tb gets deleted since it is a memory
# hog; deleting everything else is just for thoroughness
finally:
del exc_type, exc_value, exc_tb
else:
if __debug__:
self._note("%s.__bootstrap(): normal return", self)
finally:
# Prevent a race in
# test_threading.test_no_refcycle_through_target when
# the exception keeps the target alive past when we
# assert that it's dead.
self.__exc_clear()
finally:
with _active_limbo_lock:
self.__stop()
try:
# We don't call self.__delete() because it also
# grabs _active_limbo_lock.
del _active[_get_ident()]
except:
pass
示例6: __bootstrap
def __bootstrap(self):
try:
self.__started = True
_active_limbo_lock.acquire()
_active[_get_ident()] = self
del _limbo[self]
_active_limbo_lock.release()
if __debug__:
self._note("%s.__bootstrap(): thread started", self)
if _trace_hook:
self._note("%s.__bootstrap(): registering trace hook", self)
_sys.settrace(_trace_hook)
if _profile_hook:
self._note("%s.__bootstrap(): registering profile hook", self)
_sys.setprofile(_profile_hook)
try:
self.run()
except SystemExit:
if __debug__:
self._note("%s.__bootstrap(): raised SystemExit", self)
except:
if __debug__:
self._note("%s.__bootstrap(): unhandled exception", self)
# If sys.stderr is no more (most likely from interpreter
# shutdown) use self.__stderr. Otherwise still use sys (as in
# _sys) in case sys.stderr was redefined since the creation of
# self.
if _sys:
_sys.stderr.write("Exception in thread %s:\n%s\n" %
(self.getName(), _format_exc()))
else:
# Do the best job possible w/o a huge amt. of code to
# approximate a traceback (code ideas from
# Lib/traceback.py)
exc_type, exc_value, exc_tb = self.__exc_info()
try:
print>>self.__stderr, (
"Exception in thread " + self.getName() +
" (most likely raised during interpreter shutdown):")
print>>self.__stderr, (
"Traceback (most recent call last):")
while exc_tb:
print>>self.__stderr, (
' File "%s", line %s, in %s' %
(exc_tb.tb_frame.f_code.co_filename,
exc_tb.tb_lineno,
exc_tb.tb_frame.f_code.co_name))
exc_tb = exc_tb.tb_next
print>>self.__stderr, ("%s: %s" % (exc_type, exc_value))
# Make sure that exc_tb gets deleted since it is a memory
# hog; deleting everything else is just for thoroughness
finally:
del exc_type, exc_value, exc_tb
else:
if __debug__:
self._note("%s.__bootstrap(): normal return", self)
finally:
self.__stop()
try:
self.__delete()
except:
pass
示例7: __bootstrap
def __bootstrap(self):
try:
self.__started = True
_active_limbo_lock.acquire()
_active[_get_ident()] = self
del _limbo[self]
_active_limbo_lock.release()
if _trace_hook:
self._note('%s.__bootstrap(): registering trace hook', self)
_sys.settrace(_trace_hook)
if _profile_hook:
self._note('%s.__bootstrap(): registering profile hook', self)
_sys.setprofile(_profile_hook)
try:
self.run()
except SystemExit:
pass
except:
if _sys:
_sys.stderr.write('Exception in thread %s:\n%s\n' % (self.getName(), _format_exc()))
else:
exc_type, exc_value, exc_tb = self.__exc_info()
try:
print >> self.__stderr, 'Exception in thread ' + self.getName() + ' (most likely raised during interpreter shutdown):'
print >> self.__stderr, 'Traceback (most recent call last):'
while exc_tb:
print >> self.__stderr, ' File "%s", line %s, in %s' % (exc_tb.tb_frame.f_code.co_filename, exc_tb.tb_lineno, exc_tb.tb_frame.f_code.co_name)
exc_tb = exc_tb.tb_next
print >> self.__stderr, '%s: %s' % (exc_type, exc_value)
finally:
del exc_type
del exc_value
del exc_tb
finally:
self.__stop()
try:
self.__delete()
except:
pass