diff options
author | Barry Warsaw <barry@python.org> | 2017-10-05 16:11:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-05 16:11:18 (GMT) |
commit | 36c1d1f1e52ba54007cbecb42c5599e5ff62aa52 (patch) | |
tree | 317c296450800bfb25851dd92a62050e26c4c4fd /Doc/library/sys.rst | |
parent | 4d071897880b7e84e1a217ebe19971c118316970 (diff) | |
download | cpython-36c1d1f1e52ba54007cbecb42c5599e5ff62aa52.zip cpython-36c1d1f1e52ba54007cbecb42c5599e5ff62aa52.tar.gz cpython-36c1d1f1e52ba54007cbecb42c5599e5ff62aa52.tar.bz2 |
PEP 553 built-in breakpoint() function (bpo-31353) (#3355)
Implement PEP 553, built-in breakpoint() with support from sys.breakpointhook(), along with documentation and tests. Closes bpo-31353
Diffstat (limited to 'Doc/library/sys.rst')
-rw-r--r-- | Doc/library/sys.rst | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 85f3136..aa7bd47 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -109,6 +109,40 @@ always available. This function should be used for internal and specialized purposes only. +.. function:: breakpointhook() + + This hook function is called by built-in :func:`breakpoint`. By default, + it drops you into the :mod:`pdb` debugger, but it can be set to any other + function so that you can choose which debugger gets used. + + The signature of this function is dependent on what it calls. For example, + the default binding (e.g. ``pdb.set_trace()``) expects no arguments, but + you might bind it to a function that expects additional arguments + (positional and/or keyword). The built-in ``breakpoint()`` function passes + its ``*args`` and ``**kws`` straight through. Whatever + ``breakpointhooks()`` returns is returned from ``breakpoint()``. + + The default implementation first consults the environment variable + :envvar:`PYTHONBREAKPOINT`. If that is set to ``"0"`` then this function + returns immediately; i.e. it is a no-op. If the environment variable is + not set, or is set to the empty string, ``pdb.set_trace()`` is called. + Otherwise this variable should name a function to run, using Python's + dotted-import nomenclature, e.g. ``package.subpackage.module.function``. + In this case, ``package.subpackage.module`` would be imported and the + resulting module must have a callable named ``function()``. This is run, + passing in ``*args`` and ``**kws``, and whatever ``function()`` returns, + ``sys.breakpointhook()`` returns to the built-in :func:`breakpoint` + function. + + Note that if anything goes wrong while importing the callable named by + :envvar:`PYTHONBREAKPOINT`, a :exc:`RuntimeWarning` is reported and the + breakpoint is ignored. + + Also note that if ``sys.breakpointhook()`` is overridden programmatically, + :envvar:`PYTHONBREAKPOINT` is *not* consulted. + + .. versionadded:: 3.7 + .. function:: _debugmallocstats() Print low-level information to stderr about the state of CPython's memory @@ -187,14 +221,19 @@ always available. customized by assigning another three-argument function to ``sys.excepthook``. -.. data:: __displayhook__ +.. data:: __breakpointhook__ + __displayhook__ __excepthook__ - These objects contain the original values of ``displayhook`` and ``excepthook`` - at the start of the program. They are saved so that ``displayhook`` and - ``excepthook`` can be restored in case they happen to get replaced with broken + These objects contain the original values of ``breakpointhook``, + ``displayhook``, and ``excepthook`` at the start of the program. They are + saved so that ``breakpointhook``, ``displayhook`` and ``excepthook`` can be + restored in case they happen to get replaced with broken or alternative objects. + .. versionadded:: 3.7 + __breakpointhook__ + .. function:: exc_info() |