Check what a running process is doing: print stack trace of an uninstrumented Python program

前端 未结 5 1691
[愿得一人]
[愿得一人] 2021-02-07 02:07

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 t

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-07 02:47

    lptrace does exactly that. It allows you to attach to a running Python process and show currently executing functions, like strace does for system calls. You can call it like this:

    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.

提交回复
热议问题