我使用子进程
下面有ping函数def ping_sub1(a):
with open(os.devnull, "wb") as limbo:
for ip in a:
result = subprocess.Popen(["ping", "-c", "1", "-w", "1", ip], stdout=limbo, stderr=limbo).wait()
if result:
a.remove(ip)
return a
我和' a'列表如下123.123.123.123没有响应。看起来像 它已从列表中删除但随后程序停止...只有在所有地址都响应时才能正常工作。
>>> a=['10.29.1.1', '123.123.123.123', '123.123.123.123', '10.29.21.208']
>>> pingtest4.ping_sub1(a)
['10.29.1.1', '123.123.123.123', '10.29.21.208']
>>> pingtest4.ping_sub1(a)
['10.29.1.1', '10.29.21.208']
>>> pingtest4.ping_sub1(a)
['10.29.1.1', '10.29.21.208']
>>>
请告知