serhii.net

In the middle of the desert you can say anything you want

19 Sep 2025

PDB decorator function

def pdb_debug(
    main_func,
):  # pylint: disable=missing-function-docstring, broad-exception-caught
    """Run a function, optionally drop to pdb on exception"""

    def wrapper():
        import pdb
        import sys
        import traceback

        try:
            main_func()
        except Exception as e:
            # PDB is actually read from .env
            if PDB:
                _, _, tb = sys.exc_info()
                traceback.print_exc()
                pdb.post_mortem(tb)
            else:
                raise e

    return wrapper

A spin over the usual: 220214-1756 python run pdb on exception

Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus