當前位置: 首頁>>代碼示例>>Python>>正文


Python ipdb.post_mortem方法代碼示例

本文整理匯總了Python中ipdb.post_mortem方法的典型用法代碼示例。如果您正苦於以下問題:Python ipdb.post_mortem方法的具體用法?Python ipdb.post_mortem怎麽用?Python ipdb.post_mortem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ipdb的用法示例。


在下文中一共展示了ipdb.post_mortem方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: register_debug_hook

# 需要導入模塊: import ipdb [as 別名]
# 或者: from ipdb 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

示例2: post_mortem

# 需要導入模塊: import ipdb [as 別名]
# 或者: from ipdb import post_mortem [as 別名]
def post_mortem(traceback):
    """Work with an exception in a post-mortem debugger.

    Try to use `ipdb` first, falling back to `pdb`.
    """
    try:
        from ipdb import post_mortem
    except ImportError:
        from pdb import post_mortem

    message = "Entering post-mortem debugger. Type `help` for help."
    redline = colorized("{autored}%s{/autored}") % "{0:=^{1}}"

    print()
    print(redline.format(" CRASH! ", len(message)))
    print(message)
    print(redline.format("", len(message)))
    print()

    post_mortem(traceback) 
開發者ID:maas,項目名稱:python-libmaas,代碼行數:22,代碼來源:__init__.py

示例3: after_step

# 需要導入模塊: import ipdb [as 別名]
# 或者: from ipdb import post_mortem [as 別名]
def after_step(context, step):
    if BEHAVE_DEBUG_ON_ERROR and step.status == "failed":
        # -- ENTER DEBUGGER: Zoom in on failure location.
        # NOTE: Use IPython debugger, same for pdb (basic python debugger).
        try:
            import ipdb as pdb
        except ImportError:
            import pdb

        if getattr(context, "browser", None):
            pprint(context.browser.driver.get_log('browser')[-10:])
            print("Current Screen: {}".format(context.browser.screenshot()))

        pdb.post_mortem(step.exc_traceback) 
開發者ID:beavyHQ,項目名稱:beavy,代碼行數:16,代碼來源:environment.py

示例4: _debug_on_error

# 需要導入模塊: import ipdb [as 別名]
# 或者: from ipdb import post_mortem [as 別名]
def _debug_on_error(context, step):
    if context.config.userdata.getbool("debug"):
        try:
            import ipdb
            ipdb.post_mortem(step.exc_traceback)
        except ImportError:
            import pdb
            pdb.post_mortem(step.exc_traceback) 
開發者ID:leapcode,項目名稱:bitmask-dev,代碼行數:10,代碼來源:environment.py

示例5: handle_exception

# 需要導入模塊: import ipdb [as 別名]
# 或者: from ipdb import post_mortem [as 別名]
def handle_exception(self, e):
        print("\nException:", e)
        traceback.print_exc(file=sys.stdout)

        answer = questionary.select(
            'Now what?',
            choices=[
                'Restart browser',
                'Debug with ipdb',
                'Debug with pdb',
                'Exit',
            ]
        ).ask()

        if answer == 'Debug with ipdb':
            try:
                import ipdb
            except ImportError:
                print('Please run "pip install ipdb" to install ipdb')
                sys.exit(1)
            ipdb.post_mortem()
        elif answer == 'Debug with pdb':
            import pdb
            pdb.post_mortem()
        elif answer == 'Restart browser':
            self.worker.restart()
            return

        self.worker.close()
        sys.exit() 
開發者ID:scriptotek,項目名稱:alma-slipsomat,代碼行數:32,代碼來源:shell.py

示例6: after_step

# 需要導入模塊: import ipdb [as 別名]
# 或者: from ipdb import post_mortem [as 別名]
def after_step(context, step):
    if BEHAVE_DEBUG_ON_ERROR and step.status == "failed":
        # -- ENTER DEBUGGER: Zoom in on failure location.
        # NOTE: Use IPython debugger, same for pdb (basic python debugger).
        import ipdb
        ipdb.post_mortem(step.exc_traceback) 
開發者ID:thelastpickle,項目名稱:cassandra-medusa,代碼行數:8,代碼來源:environment.py

示例7: yield_values

# 需要導入模塊: import ipdb [as 別名]
# 或者: from ipdb import post_mortem [as 別名]
def yield_values(extract, *args, **kw):
    """ Yields ``Value`` objects extracted using ``extract``. """
    exc_info = ()

    try:
        returned = extract(*args, **kw)
        for walker in walk(returned, should_iter_unless_list):
            for value in walker:
                yield Value(value)
    except BdbQuit:
        raise
    except Exception as exc:
        exc_info = sys.exc_info()
        yield Value(exc)

    if any(exc_info) and (Value.exit_on_exc or Value.debug_on_exc):
        if Value.debug_on_exc:
            import traceback
            try:
                import ipdb as pdb
            except ImportError:
                import pdb
                assert pdb
            traceback.print_tb(exc_info[2])
            pdb.post_mortem(exc_info[2])
        else:
            reraise(exc_info[0], exc_info[1], exc_info[2]) 
開發者ID:eBay,項目名稱:wextracto,代碼行數:29,代碼來源:value.py

示例8: after_step

# 需要導入模塊: import ipdb [as 別名]
# 或者: from ipdb import post_mortem [as 別名]
def after_step(context, step):
    # from https://github.com/behave/behave/blob/master/docs/tutorial.rst#
    #       debug-on-error-in-case-of-step-failures
    # and https://stackoverflow.com/a/22344473/399726
    if BEHAVE_DEBUG_ON_ERROR and step.status == "failed":
        # -- ENTER DEBUGGER: Zoom in on failure location.
        # NOTE: Use IPython debugger, same for pdb (basic python debugger).
        import ipdb
        ipdb.post_mortem(step.exc_traceback) 
開發者ID:codeforamerica,項目名稱:intake,代碼行數:11,代碼來源:environment.py

示例9: _custom_exception_hook

# 需要導入模塊: import ipdb [as 別名]
# 或者: from ipdb import post_mortem [as 別名]
def _custom_exception_hook(type, value, tb):
    if hasattr(sys, 'ps1') or not sys.stderr.isatty():
        # we are in interactive mode or we don't have a tty-like
        # device, so we call the default hook
        sys.__excepthook__(type, value, tb)
    else:
        import traceback, ipdb
        # we are NOT in interactive mode, print the exception...
        traceback.print_exception(type, value, tb)
        # ...then start the debugger in post-mortem mode.
        ipdb.post_mortem(tb) 
開發者ID:vacancy,項目名稱:Jacinle,代碼行數:13,代碼來源:debug.py

示例10: _excepthook

# 需要導入模塊: import ipdb [as 別名]
# 或者: from ipdb import post_mortem [as 別名]
def _excepthook(self, etype, evalue, etb):
        from IPython.core import ultratb
        from mayo.util import import_from_string
        ultratb.FormattedTB()(etype, evalue, etb)
        for exc in self.get('system.pdb.skip', []):
            exc = import_from_string(exc)
            if issubclass(etype, exc):
                sys.exit(-1)
        if self.get('system.pdb.use', True):
            import ipdb
            ipdb.post_mortem(etb) 
開發者ID:deep-fry,項目名稱:mayo,代碼行數:13,代碼來源:config.py

示例11: after_step

# 需要導入模塊: import ipdb [as 別名]
# 或者: from ipdb import post_mortem [as 別名]
def after_step(context, step):
    # "Given" triggers execution
    if step.step_type == 'given':
        context.interpreter.execute()

    # "When" triggers monitored execution
    if step.step_type == 'when':
        macrosteps = context.interpreter.execute()

        if not context._monitoring:
            context._monitoring = True
            context.monitored_trace = []

        context.monitored_trace.extend(macrosteps)

    # Hook to enable debugging
    if step.step_type == 'then' and step.status == 'failed' and context.config.userdata.get('debug_on_error'):
        try:
            import ipdb as pdb
        except ImportError:
            import pdb

        print('--------------------------------------------------------------')
        print('Dropping into (i)pdb.', end='\n\n')
        print('Variable context holds the current execution context of Behave')
        print('You can access the interpreter using context.interpreter, the')
        print('trace using context.trace and the monitored trace using')
        print('context.monitored_trace.')
        print('--------------------------------------------------------------')

        pdb.post_mortem(step.exc_traceback) 
開發者ID:AlexandreDecan,項目名稱:sismic,代碼行數:33,代碼來源:environment.py

示例12: after_step

# 需要導入模塊: import ipdb [as 別名]
# 或者: from ipdb import post_mortem [as 別名]
def after_step(context, step):
    if BEHAVE_DEBUG_ON_ERROR and step.status == 'failed':
        import ipdb
        ipdb.post_mortem(step.exc_traceback) 
開發者ID:Yelp,項目名稱:clusterman,代碼行數:6,代碼來源:environment.py

示例13: main

# 需要導入模塊: import ipdb [as 別名]
# 或者: from ipdb import post_mortem [as 別名]
def main(argv=sys.argv):
    program, *arguments = argv
    program = program_name_from_env(program)
    parser, options = None, None

    try:
        parser = prepare_parser(program)
        argcomplete.autocomplete(parser, exclude=("-h", "--help"))
        options = parser.parse_args(arguments)
        try:
            execute = options.execute
        except AttributeError:
            parser.error("Argument missing.")
        else:
            return execute(options)
    except KeyboardInterrupt:
        raise SystemExit(1)
    except Exception as error:
        # This is unexpected. Why? Because the CLI code raises SystemExit or
        # invokes something that raises SystemExit when it chooses to exit.
        # SystemExit does not subclass Exception, and so it would not be
        # handled here, hence this is not a deliberate exit.
        if parser is None or options is None or options.debug:
            # The user has either chosen to debug OR we crashed before/while
            # parsing arguments. Either way, let's not be terse.
            if sys.stdin.isatty() and sys.stdout.isatty():
                # We're at a fully interactive terminal so let's post-mortem.
                *_, exc_traceback = sys.exc_info()
                post_mortem(exc_traceback)
                # Exit non-zero, but quietly; dumping the traceback again on
                # the way out is confusing after doing a post-mortem.
                raise SystemExit(1)
            else:
                # Re-raise so the traceback is dumped and we exit non-zero.
                raise
        else:
            # Display a terse error message. Note that parser.error() will
            # raise SystemExit(>0) after printing its message.
            parser.error("%s" % error) 
開發者ID:maas,項目名稱:python-libmaas,代碼行數:41,代碼來源:__init__.py

示例14: after_step

# 需要導入模塊: import ipdb [as 別名]
# 或者: from ipdb import post_mortem [as 別名]
def after_step(_, step):
    if DEBUG_ON_ERROR and step.status == 'failed':
        import ipdb
        ipdb.post_mortem(step.exc_traceback) 
開發者ID:j-bennet,項目名稱:wharfee,代碼行數:6,代碼來源:environment.py

示例15: debug_on_exception

# 需要導入模塊: import ipdb [as 別名]
# 或者: from ipdb import post_mortem [as 別名]
def debug_on_exception(func):
    """
    Opens an ``ipdb`` debugging prompt at the point of failure
    when an uncaught exception is raised.

    .. warning::

        must not be in production code... only to be used for
        debugging purposes.

    Usage::

        from base import debug_on_exception

        @debug_on_exception
        def foo(a=100):
            return 1 / a

        foo(0)

    results in an ``ipdb`` prompt::

        Traceback (most recent call last):
          File "./test.py", line 8, in wrapper
            func(*args, **kwargs)
          File "./test.py", line 19, in foo
            return 1 / a
        ZeroDivisionError: integer division or modulo by zero
        > /home/me/temp/test.py(19)foo()
             18 def foo(a=100):
        ---> 19     return 1 / a
             20

        ipdb> !a
        0
        ipdb>

    """
    def ipdb_wrapper(*args, **kwargs):
        try:
            func(*args, **kwargs)
        except:
            import ipdb, traceback, sys
            type, value, tb = sys.exc_info()
            traceback.print_exc()
            ipdb.post_mortem(tb)
    return ipdb_wrapper


# ------------------- Core TestCase ------------------- 
開發者ID:cqparts,項目名稱:cqparts,代碼行數:52,代碼來源:base.py


注:本文中的ipdb.post_mortem方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。