Mac OS系统下Python多进程Debug卡死状态

介绍
TEMP.py用于启动多进程读取文件,并行处理并写入文件中.

首先利用ps aux | grep TEMP.py查找对应pid.

(virtualenv_3.6.5) localhost:other_requriment root$ ps aux | grep TEMP.py
root             10859   0.0  0.0  4286184    972 s000  S+    8:07PM   0:00.01 grep TEMP.py
root             10797   0.0  0.0  7846872   1300   ??  S     7:50PM   0:16.63 bin/python3.6 /TEMP.py
root             10796   0.0  0.1  7875000   4360   ??  S     7:50PM   0:30.04 bin/python3.6 /TEMP.py
root             10795   0.0  0.1  7875000   4256   ??  S     7:50PM   0:30.23 bin/python3.6 /TEMP.py
root             10794   0.0  0.1  7875256   4236   ??  S     7:50PM   0:29.77 bin/python3.6 /TEMP.py
root             10793   0.0  0.1  7875256   4236   ??  S     7:50PM   0:29.26 bin/python3.6 /TEMP.py
root             10792   0.0  0.0  7847908   1824   ??  S     7:50PM   0:00.10 bin/python3.6 /TEMP.py
root             10791   0.0  0.0  7853028   1336   ??  S     7:50PM   0:08.25 bin/python3.6 /TEMP.py
root             10782   0.0  0.3  7846080  24124   ??  S     7:50PM   0:01.77 bin/python3.6 /TEMP.py

(virtualenv_3.6.5) localhost:$ pstree 10782
-+- 10782 root bin/python3.6 PROJECT/TEMP.py
 |--- 10791 root bin/python3.6 PROJECT/TEMP.py
 |--- 10792 root bin/python3.6 PROJECT/TEMP.py
 |--- 10793 root bin/python3.6 PROJECT/TEMP.py
 |--- 10794 root bin/python3.6 PROJECT/TEMP.py
 |--- 10795 root bin/python3.6 PROJECT/TEMP.py
 |--- 10796 root bin/python3.6 PROJECT/TEMP.py
 \--- 10797 root bin/python3.6 PROJECT/TEMP.py

使用dtruss进行进程情况查看(类似Linux系统中的strace).

(virtualenv_3.6.5) localhost:$ sudo dtruss -p 10782
dtrace: system integrity protection is on, some features will not be available

SYSCALL(args)            = return
gettimeofday(0x7000046A9C68, 0x0, 0x0)           = 0 0
gettimeofday(0x7000047AC538, 0x0, 0x0)           = 0 0
psynch_cvwait(0x7FE75A178168, 0x100000100, 0x0)          = -1 Err#316
gettimeofday(0x7000046A9C68, 0x0, 0x0)           = 0 0
psynch_cvwait(0x7FE75A178168, 0x100000100, 0x0)          = -1 Err#316

查询子进程10791 – 10797
发现除了10792报错和主进程一样之外, 其他子进程均和10793一样, 没有报错.

(virtualenv_3.6.5) localhost:other_requriment didisudo dtruss -p 10792
dtrace: system integrity protection is on, some features will not be available

SYSCALL(args)            = return
gettimeofday(0x7FFEE9E28BA8, 0x0, 0x0)           = 0 0
psynch_cvwait(0x7FE75A236A88, 0x100000100, 0x0)          = -1 Err#316

(virtualenv_3.6.5) localhost:other_requriment didi sudo dtruss -p 10793
dtrace: system integrity protection is on, some features will not be available

SYSCALL(args)            = return

Linux系统下可以进入/proc/$PID/ 下 cat status 或者进入fd进行查看, 但是Mac OS系统下没有/proc目录, 所以根据Mac OS X equivalent of VirtualQuery or /proc/pid/maps?的推荐, 使用**vmmap**进行查看(需要root权限). 命令输出的信息较多(看不太懂这里的内容输出).

Stack Overflow上有类似的问题
Interpret dtruss output like “psynch_cvwait(…) = -1 Err#316”
问题中的回答提到

/*
 *  psynch_cvwait: This system call is used for psynch cvar waiters to block in kernel.
 */
int
psynch_cvwait(__unused proc_t p,
              struct psynch_cvwait_args * uap,
              uint32_t * retval)

也就是说, psynch_cswait是用来允许psynch cvar waiters在内核中block的.

Linux上调试类似问题
调试卡死的Python进程
用strace查找进程卡死原因

发表评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据