English 中文(简体)
检查一个运行过程正在做些什么:对一个无人入侵的“灰色”节目的打印中继痕迹
原标题:Check what a running process is doing: print stack trace of an uninstrumented Python program

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.

诸如 st、ack和 g等常规脱胎工具对沙尔法并不有用。 多数等级框架仅包含口译法的功能,如PyEval_EvalFrame Ex and PyEval_Eval 法典 否则,就没有给你任何关于处决的 h。

问题回答

https://stackoverflow.com/questions/132058/showing-the-stack-trace- from-a-running-python-application>。 a. 显示从浮游应用中 st痕的情况适用于这种情况:

py-spy (https://github.com/benfred/py-spy) has a few useful tools for inspecting running Python processes. In particular, py-spy dump will print a stack trace (including function, file, and line) for every thread.

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

然后,在提出密码后:

A password should be set to secure debugger client-server communication.
Please type a password:mypassword

您可以启动双双双双双双双双双双双双双双双双双双双双双双双双双双双双双双双双双双双双双向,然后向(或档案和”程序。

可在位于苯胺等苯胺系统中使用良好的旧的银,见

也有极好的PyCharm IDE(可免费获得的社区版本),可随从民主选举学会内部的一场露天过程而使用位于一旁的Pdb 4, 参看这一博客条目:

rel=“nofollow noretinger”>lptrace确实如此。 它允许你遵守一个波什进程,并显示目前执行的职能,例如<条码>、对系统电话的使用。 你可以这样说:

vagrant@precise32:/vagrant$ sudo python lptrace -p $YOUR_PID
fileno (/usr/lib/python2.7/SocketServer.py:438)
meth (/usr/lib/python2.7/socket.py:223)

fileno (/usr/lib/python2.7/SocketServer.py:438)
meth (/usr/lib/python2.7/socket.py:223)
...

Note that it requires gdb to run, which isn t available on every server machine.

You can use madbg (by me). It is a python debugger that allows you to attach to a running python program and debug it in your current terminal. It is similar to pyrasite and pyringe, but newer, doesn t require gdb, and uses IPython for the debugger (which means colors and autocomplete).

To see the stack trace of a running program, you could run:

madbg attach <pid>

And in the debugger shell, enter: bt

It s possible to debug Python with gdb. See Chapter 22: gdb Support in the Python Developer’s Guide.

例如,在Debian和3.7处:

# apt-get update -y && apt-get install gdb python3.7-dbg
# gdb

(gdb) source /usr/share/gdb/auto-load/usr/bin/python3.7-gdb.py
(gdb) attach <PID>
(gdb) py-bt

也可以使用satella。 冰边效应是,每个阵列的每个地方变量都将予以印刷。 守则是:

from satella.instrumentation import Traceback
import sys

for frame_no, frame in sys._current_frames().items():
    sys.stderr.write("For stack frame %s" % (frame_no,))
    tb = Traceback(frame)
    tb.pretty_print()
sys.stderr.write("End of stack frame dump
")




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签