一次线上针对python 死锁问题进行了追踪, 这里进行记录.

  1. 更新镜像源: 我使用了清华大学的开源镜像站 https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/ vim /etc/apt/sources.list

    # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
    

    sudo apt-get update

  2. 下载gdb套件 sudo apt-get install gdb python2.7-dbg

  3. 确定进程

    xxxxx:xxxx# ps -ef | grep python
    root          58       1  0 14:23 ?        00:00:01 python launch.py
    root         130      58  0 14:23 ?        00:00:06 python launch.py
    root         131      58  0 14:23 ?        00:00:22 python launch.py
    root         132      58  0 14:23 ?        00:00:17 python launch.py
    root         133      58  0 14:23 ?        00:00:17 python launch.py
    root         134      58  0 14:23 ?        00:00:17 python launch.py
    root        6461     383  0 16:01 pts/0    00:00:00 grep python
    
  4. 看下进程的状态:

    strace -T -tt -e trace=all -p 131
    xxx(xxxx):log# strace -T -tt -e trace=all -p  130 
    Process 130 attached
    15:34:41.294497 futex(0x1b19c20, FUTEX_WAIT_PRIVATE, 0, NULL
    
  5. gdb调试

    sudo gdb python -p 131
    info threads 
    thread 1 
    py-list 
    info frame
    py-up
    

    相关gdb技巧不叙述. 参考地址: blog