0

I have ping function below using subproces

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

I run with 'a' list below where 123.123.123.123 is not responsive. It looks like it's removed from list but then program stops...it works only fine if all addresses are responsive.

>>> 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']
>>> 

Please advise

irom
  • 3,316
  • 14
  • 54
  • 86

0 Answers0