Ever wondered how to debug a hanging test in #Python?
pip install pytest-timeout
pytest --timeout=N_SECONDS
To dump the whole stack trace you can add `--timeout_method=thread` as well.
Here is an example:
Just had a quite emotional, personal conversation with the debugger. I tried to inspect the stack, the heap and the fault address.
Interestingly I felt heard & warm. Never tried therapy before but this is probably it? Try it especially if you usually just use it to step over.
For over a decade the git grep command on macOS handled incorrectly regular expressions with UTF-8 characters. Here is how I debugged and fixed the problem. The fix will be released with Git 2.39. https://t.co/ixkq9YgRq9
@zkat__@gesa • Add unit tests
• Add assertions
• Refactor the code
• Consider post-portem debugging
• Consider attaching to the process, once the bug manifests itself
In general, all bugs are tractable given sufficient effort.
@zkat__@gesa • Add logging statements.
• If these also hide the bug, log into memory, and then dump the in-memory logs
• If you're debugging a non-optimized debug build (e.g. -O0), debug an optimized production build (e.g. -Ox)
• Exhaustively review/lint the code associated with the bug.
Logging always you to see the full state history. Noisy logs + grep is powerful,
Debugging with breakpoints is ephemeral and relies on a lot of short-term memory. Easy to get interrupted or miss something and have to do the whole sequence again.
"Rather than alchemy, methodical troubleshooting", or "Finding a needle in a haystack by running git bisect on synthetic commits" https://t.co/ClRP9Tf6g3
@sysarmy Web searching is item #2 in the Effective Debugging book. The restart option, often works, but is in most cases a temporary solution. It is therefore unsuitable for production systems, because it leads to more toil.
You know you're in trouble when you search for an error message and, rather than obtaining StackOverflow results, all you get are still-open GitHub issues and a Reddit page.
[ Image credit @ThePracticalDev ]
@coderadda So true! See the "Effective Debugging" book, Chapter 2 (General-Purpose Methods an Practices), Item 9 (Set Yourself Up for Debugging Success), p. 24: "Sleep in a difficult problem".