本文整理匯總了Python中pdb.post_mortem方法的典型用法代碼示例。如果您正苦於以下問題:Python pdb.post_mortem方法的具體用法?Python pdb.post_mortem怎麽用?Python pdb.post_mortem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pdb
的用法示例。
在下文中一共展示了pdb.post_mortem方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: set_trace
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import post_mortem [as 別名]
def set_trace():
"""Call pdb.set_trace in the caller's frame.
First restore sys.stdout and sys.stderr. Note that the streams are
NOT reset to whatever they were before the call once pdb is done!
"""
import pdb
for stream in 'stdout', 'stderr':
output = getattr(sys, stream)
orig_output = getattr(sys, '__%s__' % stream)
if output != orig_output:
# Flush the output before entering pdb
if hasattr(output, 'getvalue'):
orig_output.write(output.getvalue())
orig_output.flush()
setattr(sys, stream, orig_output)
exc, tb = sys.exc_info()[1:]
if tb:
if isinstance(exc, AssertionError) and exc.args:
# The traceback is not printed yet
print_exc()
pdb.post_mortem(tb)
else:
pdb.Pdb().set_trace(sys._getframe().f_back)
示例2: _HandleRunPluginException
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import post_mortem [as 別名]
def _HandleRunPluginException(self, ui_renderer, e):
"""Handle all exceptions thrown by logging to the console."""
if isinstance(e, plugin.InvalidArgs):
self.logging.fatal("Invalid Args: %s" % e)
elif isinstance(e, plugin.PluginError):
self.logging.fatal(str(e))
elif isinstance(e, (KeyboardInterrupt, plugin.Abort)):
logging.error("Aborted\r\n")
else:
error_status = traceback.format_exc()
# Report the error to the renderer.
self.logging.fatal(error_status)
# If anything goes wrong, we break into a debugger here.
if self.GetParameter("debug"):
pdb.post_mortem(sys.exc_info()[2])
# This method is called from the exception handler - this bare raise
# will preserve backtraces.
raise # pylint: disable=misplaced-bare-raise
示例3: warn
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import post_mortem [as 別名]
def warn(exc, nav, repl_pairs, local_opt, node):
"""
Failure_callback for NavigatorOptimizer: print traceback.
"""
if config.on_opt_error != 'ignore':
_logger.error("Optimization failure due to: %s" % str(local_opt))
_logger.error("node: %s" % str(node))
_logger.error("TRACEBACK:")
_logger.error(traceback.format_exc())
if config.on_opt_error == 'pdb':
pdb.post_mortem(sys.exc_info()[2])
elif isinstance(exc, AssertionError) or config.on_opt_error == 'raise':
# We always crash on AssertionError because something may be
# seriously wrong if such an exception is raised.
raise exc
示例4: easy_test
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import post_mortem [as 別名]
def easy_test(plugin_list=None, debug=True):
logger.setLevel(logging.DEBUG)
logging.getLogger().setLevel(logging.INFO)
try:
if not plugin_list:
import __main__
logger.info('Loading classes from {}'.format(__main__))
from . import plugins
plugin_list = plugins.from_module(__main__)
plugin_list = list(plugin_list)
for plug in plugin_list:
plug.test()
plug.log.info('My tests passed!')
logger.info('All tests passed for {} plugins!'.format(len(plugin_list)))
except Exception:
if not debug:
raise
pdb.post_mortem()
示例5: enable_debugging
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import post_mortem [as 別名]
def enable_debugging():
"""Adds the paremeter ``--pdb`` (or ``-P``) to enable dropping into PDB"""
def decorator(func):
@arg('-P', '--pdb', help="Drop into debugger on exception")
@utils.wraps(func)
def wrapper(*args, pdb=False, **kwargs):
try:
func(*args, **kwargs)
except Exception as e:
logger.exception("Dropping into debugger")
if pdb:
import pdb
pdb.post_mortem()
else:
raise
return wrapper
return decorator
示例6: setup_exceptionhook
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import post_mortem [as 別名]
def setup_exceptionhook():
"""
Overloads default sys.excepthook with our exceptionhook handler.
If interactive, our exceptionhook handler will invoke pdb.post_mortem;
if not interactive, then invokes default handler.
"""
def _pdb_excepthook(type, value, tb):
if is_interactive():
import traceback
import pdb
traceback.print_exception(type, value, tb)
# print()
pdb.post_mortem(tb)
else:
lgr.warn(
"We cannot setup exception hook since not in interactive mode")
sys.excepthook = _pdb_excepthook
示例7: register_debug_hook
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import post_mortem [as 別名]
def register_debug_hook():
import traceback
def info(type, value, tb):
if hasattr(sys, 'ps1') or not sys.stderr.isatty():
sys.__excepthook__(type, value, tb)
else:
try:
import ipdb as pdb_api
except ImportError:
import pdb as pdb_api
traceback.print_exception(type, value, tb)
pdb_api.post_mortem(tb)
sys.excepthook = info
logging.basicConfig(level="DEBUG")
示例8: _debuginit
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import post_mortem [as 別名]
def _debuginit(self, exc_value=None, exc_type=None, exc_tb=None,
captureVars=False,
Failure__init__=Failure.__init__):
"""
Initialize failure object, possibly spawning pdb.
"""
if (exc_value, exc_type, exc_tb) == (None, None, None):
exc = sys.exc_info()
if not exc[0] == self.__class__ and DO_POST_MORTEM:
try:
strrepr = str(exc[1])
except:
strrepr = "broken str"
print("Jumping into debugger for post-mortem of exception '%s':" % (strrepr,))
import pdb
pdb.post_mortem(exc[2])
Failure__init__(self, exc_value, exc_type, exc_tb, captureVars)
示例9: setUp
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import post_mortem [as 別名]
def setUp(self):
"""
Override pdb.post_mortem so we can make sure it's called.
"""
# Make sure any changes we make are reversed:
post_mortem = pdb.post_mortem
if _shouldEnableNewStyle:
origInit = failure.Failure.__init__
else:
origInit = failure.Failure.__dict__['__init__']
def restore():
pdb.post_mortem = post_mortem
if _shouldEnableNewStyle:
failure.Failure.__init__ = origInit
else:
failure.Failure.__dict__['__init__'] = origInit
self.addCleanup(restore)
self.result = []
pdb.post_mortem = self.result.append
failure.startDebugMode()
示例10: handle_exceptions
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import post_mortem [as 別名]
def handle_exceptions(func: Callable, logger: Any, with_debugger: bool) -> Callable:
"""Drops a user into an interactive debugger if func raises an error."""
@functools.wraps(func)
def wrapped(*args, **kwargs):
try:
return func(*args, **kwargs)
except (BdbQuit, KeyboardInterrupt):
raise
except Exception as e:
logger.exception("Uncaught exception {}".format(e))
if with_debugger:
import pdb
import traceback
traceback.print_exc()
pdb.post_mortem()
else:
raise
return wrapped
示例11: send_state_update
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import post_mortem [as 別名]
def send_state_update(self):
try:
update = dict()
new_state = self.application.current_state
new_state_generation = self.application.current_state_generation
prev_state = self.prev_state
prev_state_generation = self.prev_state_generation
for k, v in new_state.items():
generation = new_state_generation[k]
if prev_state_generation.get(k) != generation:
prev_state_generation[k] = generation
update[k] = v
for k, v in prev_state.items():
if k not in new_state:
update[k] = None
if len(update) > 0:
self.write_message(
json.dumps(
dict(type='state_update', state=update),
default=json_encode_state))
prev_state.update(update)
except:
traceback.print_exc()
pdb.post_mortem()
示例12: _handle_reconciler_loaded
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import post_mortem [as 別名]
def _handle_reconciler_loaded(self, loaded_future):
try:
loaded_reconciler = loaded_future.result()
generation = self.next_generation()
self.set_state(
errors=(generation, len(loaded_reconciler.errors)),
invalid=(generation, len(loaded_reconciler.invalid_references)),
accounts=sorted(loaded_reconciler.editor.accounts.keys()),
journal_filenames=sorted(
list(loaded_reconciler.editor.journal_filenames)))
self.current_errors = loaded_reconciler.errors
self.current_invalid = loaded_reconciler.invalid_references
self.start_check_modification_observer(loaded_reconciler)
self.get_next_candidates(new_pending=True)
except:
traceback.print_exc()
pdb.post_mortem()
示例13: handle_select_candidate
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import post_mortem [as 別名]
def handle_select_candidate(self, msg):
try:
if (self.next_candidates is not None and msg['generation'] ==
self.current_state['candidates_generation']):
index = msg['index']
if index >= 0 and index < len(self.next_candidates.candidates):
candidate = self.next_candidates.candidates[index]
ignore = msg.get('ignore', None) is True
result = self.reconciler.loaded_future.result(
).accept_candidate(
candidate,
ignore=ignore,
)
self._notify_modified_files(result.modified_filenames)
self.get_next_candidates(new_pending=True)
return result.new_entries
except:
traceback.print_exc()
print('got error')
pdb.post_mortem()
示例14: _debuginit
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import post_mortem [as 別名]
def _debuginit(self, exc_value=None, exc_type=None, exc_tb=None,
captureVars=False,
Failure__init__=Failure.__init__):
"""
Initialize failure object, possibly spawning pdb.
"""
if (exc_value, exc_type, exc_tb) == (None, None, None):
exc = sys.exc_info()
if not exc[0] == self.__class__ and DO_POST_MORTEM:
try:
strrepr = str(exc[1])
except:
strrepr = "broken str"
print("Jumping into debugger for post-mortem of exception '%s':" %
(strrepr,))
import pdb
pdb.post_mortem(exc[2])
Failure__init__(self, exc_value, exc_type, exc_tb, captureVars)
示例15: main
# 需要導入模塊: import pdb [as 別名]
# 或者: from pdb import post_mortem [as 別名]
def main():
config = Configuration()
debug = False
try:
debug = config.bootstrap(environ=os.environ)
if debug:
logger.debug("Debug mode enabled.")
exit(wrapped_main(config))
except pdb.bdb.BdbQuit:
logger.info("Graceful exit from debugger.")
except UserError as e:
logger.critical("%s", e)
exit(e.exit_code)
except Exception:
logger.exception('Unhandled error:')
if debug and sys.stdout.isatty():
logger.debug("Dropping in debugger.")
pdb.post_mortem(sys.exc_info()[2])
else:
logger.error(
"Please file an issue at "
"https://github.com/dalibo/ldap2pg/issues with full log.",
)
exit(os.EX_SOFTWARE)