检查正在运行的进程正在做什么:打印未跟踪的Python程序的堆栈跟踪 [英] Check what a running process is doing: print stack trace of an uninstrumented Python program
问题描述
传统的调试工具(如strace,pstack和gdb)对Python代码不是很有用。大多数堆栈框架只包含解释器代码(如PyEval_EvalFrameEx和PyEval_EvalCodeEx)的函数,它不会在.py文件中给出任何提示。
从正在运行的Python应用程序中显示堆栈跟踪适用于这种情况:
-
吡虫啉(这是为我工作的):
$ sudo pip install pyrasite
$ echo 0 | sudo tee / proc / sys / kernel / yama / ptrace_scope
$ sudo pyrasite 16262 dump_stacks.py#将堆栈转储到python程序的stdout / stderr
- pydbattach - 无法让这个工作,但存储库 https://github.com/albertz/pydbattach 包含指向其他工具的指针
Is there a way on Linux to check what a running Python daemon process is doing? That is, without instrumenting the code and without terminating it? Preferably I'd like to get the name of the module and the line number in it that is currently running.
Conventional debugging tools such as strace, pstack and gdb are not very useful for Python code. Most stack frames just contain functions from the interpreter code like PyEval_EvalFrameEx and and PyEval_EvalCodeEx, it doesn't give you any hint on were in the .py-file the execution is.
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
这篇关于检查正在运行的进程正在做什么:打印未跟踪的Python程序的堆栈跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!