Repository navigation
Frame or Line Execution of the current psutil.Process? #3161
SummaryNumerous inspection mechanisms enable the use of profilers to detail what line of Python code is being executed at any current time through the Frames and Stack. When within the current process, the use of |
Replies: 1 comment
|
I am not sure if something like that exists. There are tools like strace on Linux or Truss on FreeBSD which allows you to "attach" to a process PID and see the system calls (read(), write(), close(), etc) in real time, as they are executed. In order to do the same for a Python process, and see exactly "where you are" in terms of code execution, you need the collaboration of the Python interpreter (sys._getframe() or whatever). In order to do what sys._getframe() does for an external python process I am afraid you have to build something from scratch, or search if there is something ready on PyPi. E.g. your Python process may listen on a TCP port on localhost, and once you connect to it it can send you the result of sys._getframe(). The client can be made interactive and accept further user input to interact with the remote process similarly to a pdb (python debugger) session. I remember I did something like this many years ago by using standard stdlib modules. |
I am not sure if something like that exists. There are tools like strace on Linux or Truss on FreeBSD which allows you to "attach" to a process PID and see the system calls (read(), write(), close(), etc) in real time, as they are executed. In order to do the same for a Python process, and see exactly "where you are" in terms of code execution, you need the collaboration of the Python interpreter (sys._getframe() or whatever). In order to do what sys._getframe() does for an external python process I am afraid you have to build something from scratch, or search if there is something ready on PyPi. E.g. your Python process may listen on a TCP port on localhost, and once you connect to it it…