Check what a running process is doing: print stack trace of an uninstrumented Python program
Some of the answers in Showing the stack trace from a running Python application are applicable in this situation:
pyrasite (this was the one that worked for me):
$ sudo pip install pyrasite$ echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope$ sudo pyrasite 16262 dump_stacks.py # dumps stacks to stdout/stderr of the python program
- pydbattach - couldn't get this to work, but the repository https://github.com/albertz/pydbattach contains pointer to other tools
- pstack reportedly prints the python stack on Solaris
winpdb allows you to attach to a running python process, but to do this, you must start the python process this way:
rpdb2 -d -r script.py
Then, after setting a password:
A password should be set to secure debugger client-server communication.Please type a password:mypassword
you could launch winpdb to File>Attach to (or File>Detach from) the process.
on POSIX systems like Linux, you can use good old GDB, see
- https://t37.net/debug-a-running-python-process-without-printf.htmland
- https://wiki.python.org/moin/DebuggingWithGdb
There's also the excellent PyCharm IDE (free community version available) that can attach to a running Python process right from within the IDE, using Pdb 4 under the hood, see this blog entry: