Skip to content

Instantly share code, notes, and snippets.

@gh640
Last active November 4, 2022 08:09
Show Gist options
  • Save gh640/5d266954e691fe5eee7fb857b65a9eee to your computer and use it in GitHub Desktop.
Save gh640/5d266954e691fe5eee7fb857b65a9eee to your computer and use it in GitHub Desktop.
Running IPython or bpython with `breakpoint()` on Python 3
#!/usr/local/bin/bash
# Use IPython.
PYTHONBREAKPOINT=IPython.terminal.debugger.set_trace python myscript.py
# Use bpython.
PYTHONBREAKPOINT=bpdb.set_trace python myscrippt.py
@gh640
Copy link
Author

gh640 commented Jun 20, 2021

@gh640
Copy link
Author

gh640 commented Jun 20, 2021

The related PEP is PEP 533.

https://www.python.org/dev/peps/pep-0553/#id11

PYTHONBREAKPOINT=some.importable.callable. In this case, sys.breakpointhook() imports the some.importable module and gets the callable object from the resulting module, which it then calls. The value may be a string with no dots, in which case it names a built-in callable, e.g. PYTHONBREAKPOINT=int. (Guido has expressed the preference for normal Python dotted-paths, not setuptools-style entry point syntax.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment