9/12/2023 0 Comments Run python script with debug![]() ![]() We can run it in the background and then run pystack remote against its PID to see what's happening in the code: We will use the following snippet that simply sleeps forever, simulating a hanging process: PyStack has 2 ways of debugging a program - either by attaching to a running process or by analyzing core dump of a crashed process. Also, to be able to trace a process, PyStack needs to send ptrace syscalls to the traced process, we can temporarily enable that with echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope.įinally, we need to install pystack itself, as well as the Pytest plugin for it. All the core dumps will then be automatically stored in /var/lib/systemd/coredump/. One of the features of PyStack is ability to inspect core dumps, so we need to enable core dump generation in our system - the simplest way to achieve that is to install systemd-coredump. Sudo apt install systemd-coredump python3-pip python3.10-venvĮcho 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope Setupīefore we start debugging, we need to do some setup: That's just a sample of reasons why PyStack is very cool. And it automatically downloads debugging information (if not available) for the particular distro. It's also able to prints local variables as part of stacktrace. It can also inspect all core dump files - which is a big statement, because core dumps can be wild. GDB can modify your code, which can be a big no-no. Now, what is so special about PyStack and why it's superior to the above-mentioned tools? For a start, unlike GDB, PyStack only reads memory (optionally stops the process), and doesn't modify it. There are also 2 Python tools austin and py-spy, those are however profilers and not debuggers. Only real alternative is GDB which isn't exactly user-friendly, and it can't debug both Python and C/C++ at the same time. under heavy load after apps has been running for X hours, etc.īut aren't there tools for this already? Well, yes, but actually no. Well, how would you debug NumPy crashing with segfault?Īnd then there are weird issues that happen in specific circumstances, e.g. That includes Python extension modules, but also libraries such as NumPy or TensorFlow which many of us use every day. When you have hanging process, you might ask yourself, "Is it doing something? Or is it stuck/dead/deadlocked?" and PyStack can help answer that.Īnother category is hybrid applications - that is - applications that combine C/C++ and Python. One such category are deadlocks or any application that gets stuck. While traditional debuggers or even simple print statements are often enough for debugging, there are bugs and issues that are much harder to track down and troubleshoot. There are many debugging tools out there, including interactive debuggers in your IDE, so you might be wondering, "Why is this even needed?" So, let's put that statement to a test and explore how to use PyStack to track down and troubleshoot all the above-mentioned issues and bugs. Now there's a tool to help you will all of that - PyStack is a powerful new debugger that - according to docs - "uses forbidden magic to let you inspect the stack frames of a running Python process or a Python core dump." Just ask yourself, "How would I debug deadlock, segmentation fault, crashing application, or a hanging process?" There are certain bugs and issues that are very hard to troubleshoot. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |