首先保证进程运行机器上有GDB和pyrasite
# Redhat, CentOS, etc
$ yum install gdb
pip install pyrasite
找到卡住的python进程ID,然后用pyrasite-shell attach上去
# Assuming process ID is 12345
$ pyrasite-shell 12345
进入 python repl 环境,然后输入
from __future__ import print_function
import sys, traceback
for thread_id, frame in sys._current_frames().items():
print('Stack for thread {}'.format(thread_id))
traceback.print_stack(frame)
print('')