当前位置: 首页>>代码示例>>Python>>正文


Python pdb.post_mortem方法代码示例

本文整理汇总了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) 
开发者ID:OpenTrading,项目名称:OpenTrader,代码行数:26,代码来源:tools.py

示例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 
开发者ID:google,项目名称:rekall,代码行数:27,代码来源:session.py

示例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 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:18,代码来源:opt.py

示例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() 
开发者ID:gsi-upm,项目名称:senpy,代码行数:20,代码来源:utils.py

示例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 
开发者ID:bioconda,项目名称:bioconda-utils,代码行数:19,代码来源:cli.py

示例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 
开发者ID:poldracklab,项目名称:pydeface,代码行数:21,代码来源:__main__.py

示例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") 
开发者ID:mobiusklein,项目名称:ms_deisotope,代码行数:18,代码来源:utils.py

示例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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:failure.py

示例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() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:test_failure.py

示例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 
开发者ID:ihmeuw,项目名称:vivarium,代码行数:22,代码来源:utilities.py

示例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() 
开发者ID:jbms,项目名称:beancount-import,代码行数:26,代码来源:webserver.py

示例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() 
开发者ID:jbms,项目名称:beancount-import,代码行数:19,代码来源:webserver.py

示例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() 
开发者ID:jbms,项目名称:beancount-import,代码行数:22,代码来源:webserver.py

示例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) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:20,代码来源:failure.py

示例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) 
开发者ID:dalibo,项目名称:ldap2pg,代码行数:27,代码来源:script.py


注:本文中的pdb.post_mortem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。