torchkit.utils.pdb_fallback

torchkit.utils.pdb_fallback.pdb_fallback(f, use_ipdb=False)[source]

Wraps a function in a pdb safety net for unexpected errors in a Python script.

When called, pdb will be automatically opened when either (a) the user hits Ctrl+C or (b) we encounter an uncaught exception. Helpful for bypassing minor errors, diagnosing problems, and rescuing unsaved models.

Example usage:

from torchkit.utils import pdb_fallback

@pdb_fallback
def main():
    # A very interesting function that might fail because we did something
    # stupid.
    ...

if __name__ == "__main__":
    main()
Parameters
  • f (CallableType) – The function to wrap.

  • use_ipdb (bool, optional) – Whether to use ipdb instead of pdb. Defaults to False.

Return type

~CallableType