# [转]python执行系统命令，怎么就卡死了？

====================================================

title： python执行系统命令，怎么就卡死了？

[En]

After the script has been developed, it is put online in the production environment after unit testing and complete process testing in the test machine. However, when it was launched, it was found that the data of the scanning task queue had not been consumed as expected, so we began to check the log, but did not find any abnormal information.

①并不是所有的任务都会卡死；

②同一个任务第一次执行卡死，第二次重新执行就正常了。

[En]

The first reason I ruled out here is the logic problem in the current code. After looking closely at the log again, I finally found a clue: every time the jam occurred on the execution of system commands, so I began to focus on the code of command calling logic.

https://github.com/momosecurity/mosec-maven-plugin

[En]

But when we restart the script for the second time, due to the existence of the cache, a large amount of download information has not been printed, so this time the program output is much less, and the above pipeline will not be filled.

stdout=PIPE 或者 stderr=PIPE 并且子进程产生了足以阻塞 OS 管道缓冲区接收更多数据的输出到管道时，将会发生死锁。当使用管道时用 Popen.communicate() 来规避它。

[En]

In order to achieve a function, the most common way is to find some code on the Internet, and then paste and copy it into our project without thinking, but this may hide a lot of hard-to-find problems. At this time, the best way is to determine whether there is something wrong with every method in the code, especially for unfamiliar methods, it may be unexpected to take a good look at the official documentation.

[*] Python官方文档 https://docs.python.org/zh-cn/3.7/library/subprocess.html

https://mp.weixin.qq.com/s/CJK-_yMo_VN1_yIUiO787w

Original: https://www.cnblogs.com/sevck/p/16494222.html
Author: sevck
Title: [转]python执行系统命令，怎么就卡死了？

(0)