Skip to content

Commit cff0e6c

Browse files
authored
Update README.md
1 parent 31ac9ce commit cff0e6c

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

README.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Better tracebacks
66

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)
88

99
```bash
1010
pip install stackprinter
@@ -67,7 +67,7 @@ I occasionally use this locally instead of a real debugger, but mostly it helps
6767
# Usage
6868

6969
## 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).
7171

7272
```python
7373
import stackprinter
@@ -105,7 +105,7 @@ configure_logging() # adds a custom log formatter, see link above
105105
try:
106106
something()
107107
except:
108-
logger.exception('The front fell off.')
108+
logger.exception('The front fell off.') # Logs a traceback along with the given message
109109
```
110110

111111
## Printing the current call stack
@@ -125,24 +125,6 @@ thread.start()
125125
stackprinter.show(thread) # or format(thread)
126126
```
127127

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.
131-
```python
132-
with stackprinter.TracePrinter(style='darkbg2'):
133-
dosomething()
134-
```
135-
136-
or
137-
```python
138-
tp = stackprinter.TracePrinter(style='darkbg2')
139-
tp.enable()
140-
dosomething()
141-
# (...) +1 million lines
142-
tp.disable()
143-
```
144-
<img src="https://raw.githubusercontent.com/cknd/stackprinter/master/trace.png" width="300">
145-
146128
## Making it stick
147129

148130
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?)
176158

177159
# Docs
178160

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.
166+
```python
167+
with stackprinter.TracePrinter(style='darkbg2'):
168+
dosomething()
169+
```
170+
171+
or
172+
```python
173+
tp = stackprinter.TracePrinter(style='darkbg2')
174+
tp.enable()
175+
dosomething()
176+
# (...) +1 million lines
177+
tp.disable()
178+
```
179+
<img src="https://raw.githubusercontent.com/cknd/stackprinter/master/trace.png" width="300">
180180

181-
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

Comments
 (0)