Attaching a process with pdb

前端 未结 3 1948
醉酒成梦
醉酒成梦 2020-12-04 17:01

I have a python script that I suspect that there is a deadlock. I was trying to debug with pdb but if I go step by step it doesn\'t get the deadlock, and by the

3条回答
  •  旧巷少年郎
    2020-12-04 17:27

    Use pyrasite:

    >>> pyrasite 172483 dump_stacks.py
    

    ...where 172483 is the PID of the running python process. The python process will then print a stack trace for each thread. One can send arbitrary Python code to be executed or open a shell.

    This is great for debugging dead locks. One can even install pyrasite after the hanging process has been started. But be aware that you should install it in the same environment to make it work.

    This is not the only tool available, but for some reason it seems to be really hard to stumble over it accidentally. It is old, but works like a charm for Python 2 and 3.

提交回复
热议问题