You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+22-23Lines changed: 22 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
# Better tracebacks
6
6
7
-
This is a more helpful version of Python's built-in exception message: It shows more code context and the current values of nearby variables. This answers many of the questions I'd ask an interactive debugger: Where in the code was the crash, what's in the relevant local variables, and why was _that_ function called with _those_ arguments. It either prints to the console or gives you a string for logging. [It's for Python 3.](https://github.com/cknd/stackprinter/issues/2#issuecomment-489458606)
7
+
This is a more helpful version of Python's built-in exception message: It shows more code context and the current values of nearby variables. That answers many of the questions I'd ask an interactive debugger: Where in the code was the crash, what's in the relevant local variables, and why was _that_ function called with _those_ arguments. It either prints to the console or gives you a string for logging. [It's for Python 3.](https://github.com/cknd/stackprinter/issues/2#issuecomment-489458606)
8
8
9
9
```bash
10
10
pip install stackprinter
@@ -67,7 +67,7 @@ I occasionally use this locally instead of a real debugger, but mostly it helps
67
67
# Usage
68
68
69
69
## Exception logging
70
-
To replace the default python crash printout, call `set_excepthook()` somewhere. This will print detailed stacktraces for any uncaught exception (to stderr, by default). You could also [make this permanent for your python installation](#making-it-stick).
70
+
To replace the default python crash printout, call `set_excepthook()` somewhere. This will print detailed stacktraces for any uncaught exception except KeyboardInterrupts (to stderr, by default). You could also [make this permanent for your python installation](#making-it-stick).
71
71
72
72
```python
73
73
import stackprinter
@@ -105,7 +105,7 @@ configure_logging() # adds a custom log formatter, see link above
105
105
try:
106
106
something()
107
107
except:
108
-
logger.exception('The front fell off.')
108
+
logger.exception('The front fell off.')# Logs a traceback along with the given message
109
109
```
110
110
111
111
## Printing the current call stack
@@ -125,24 +125,6 @@ thread.start()
125
125
stackprinter.show(thread) # or format(thread)
126
126
```
127
127
128
-
## Tracing a piece of code
129
-
130
-
More for curiosity than anything else, you can watch a piece of code execute step-by-step, printing a trace of all calls & returns 'live' as they are happening. Slows everything down though, of course.
To permanently replace the crash message for your python installation, you *could* put a file `sitecustomize.py` into the `site-packages` directory under one of the paths revealed by `python -c "import site; print(site.PREFIXES)"`, with contents like this:
@@ -176,6 +158,23 @@ as we want to inspect some thread's call stack (...or is there?)
176
158
177
159
# Docs
178
160
179
-
\*coughs\*
161
+
For now, the docs only consist of this Readme and the docstrings, [e.g. those of `format()`](https://github.com/cknd/stackprinter/blob/master/stackprinter/__init__.py#L28-L137)
162
+
163
+
## Tracing a piece of code
164
+
165
+
More for curiosity than anything else, you can watch a piece of code execute step-by-step, printing a trace of all calls & returns 'live' as they are happening. Slows everything down though, of course.
For now, just look at all the doc strings, [e.g. those of `format()`](https://github.com/cknd/stackprinter/blob/master/stackprinter/__init__.py#L28-L137)
0 commit comments