For those that find this interesting, you might also like pysnooper - I use it all the time.
https://github.com/cool-RR/PySnooper
https://python.plainenglish.io/pysnooper-stop-debugging-pyth...
"PySnooper is a poor man's debugger. If you've used Bash, it's like set -x for Python, except it's fancier."
import pysnooper
@pysnooper.snoop()
def add_up(numbers):
total = 0
for number in numbers:
total += number
return total
add_up([123, 456])
When run, PySnooper prints the activity of the decorated function or method: $ python example.py
Source path:... /home/joel/example.py
Starting var:.. numbers = [123, 456]
08:46:58.742543 call 4 def add_up(numbers):
08:46:58.742692 line 5 total = 0
New var:....... total = 0
08:46:58.742722 line 6 for number in numbers:
New var:....... number = 123
08:46:58.742755 line 7 total += number
Modified var:.. total = 123
08:46:58.742787 line 6 for number in numbers:
Modified var:.. number = 456
08:46:58.742818 line 7 total += number
Modified var:.. total = 579
08:46:58.742847 line 6 for number in numbers:
08:46:58.742876 line 8 return total
08:46:58.742898 return 8 return total
Return value:.. 579
Elapsed time: 00:00:00.000405
[1] https://github.com/cool-RR/PySnooperI'd like to add two packages I learned about recently that I like A LOT: pyrasite and PySnooper.
Use pyrasite to "attach" to an existing running Python process (i.e. you forgot to instrument the app, but it has a bug in it, how can you debug?) (1) Install pyrasite (2) Get the PID of the running process (3) Run `pyrasite dumpstackz0.py` where dumpstackz0.pycontains `import traceback; traceback.print_stack()` (4) The stacktrace will be printed in the stdout/stderr of the running application
Use PySnooper instead of print-debugging—just add a decorator to any python function to get detailed debug info like you normally would get from a full debugger: (A) code: https://github.com/cool-RR/PySnooper (B) pypi: https://pypi.org/project/PySnooper/ (C) talk: https://www.youtube.com/watch?v=XP5imOJc_TE (D) podcast: https://www.youtube.com/watch?v=VUZvgJJKor0