首先保證進程運行機器上有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('')