Windows7 Python 27 多线程中使用subprocess进行批量ping主机出现几个ping挂起现象

实现功能:
批量ping主机,将ping通的结果存入数组列表中。
具体流程是这样的:
首先将IP地址从0到255的IP存入一个queue中;而后开启多个线程处理ping操作。使用了subprocess模块的call(“ping -n 2 -w 5 %s”%ip,stdout = subprocess.PIPE)函数,同时在多线程中添加了写log文件的操作(使用的是logging日志模块).
在长时间多批次的运行过程中,偶现ping进程挂起现象,导致文件关闭不掉。不知是否有人遇到过类似的问题,怎么解决的。

讨论数量: 1
Jason990420

subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False, cwd=None, timeout=None, **other_popen_kwargs)

Note
Do not use stdout=PIPE or stderr=PIPE with this function. The child process will block if it generates enough output to a pipe to fill up the OS pipe buffer as the pipes are not being read from.

3年前 评论
Pythonhappy (楼主) 3年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!