Recovering from Lost Internet
Posted: Thu Mar 01, 2018 5:20 pm
I'm getting results that I don't understand. Using this construct in terminal works as expected:
On the first trip through, the result with Internet is instant:
Remove Internet, run, and then restore Internet:
Same code, modified to run in a plugin:
When Internet is removed, requests throws the exception and the while loop is called. However, when Internet is restored, the while loop is never broken, the ping response never reverts to 0 (zero) and instead just keeps reporting the non-zero number.
What am I missing?
- Code: Select all
import os
from time import sleep
response = '1'
while response != 0:
response = os.system("ping -c 1 google.com")
sleep(2)
print('.')
On the first trip through, the result with Internet is instant:
- Code: Select all
PING google.com (172.217.4.78): 56 data bytes
64 bytes from 172.217.4.78: icmp_seq=0 ttl=49 time=29.679 ms
--- google.com ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 29.679/29.679/29.679/0.000 ms
.
Remove Internet, run, and then restore Internet:
- Code: Select all
ping: cannot resolve google.com: Unknown host
.
ping: cannot resolve google.com: Unknown host
.
ping: cannot resolve google.com: Unknown host
.
ping: cannot resolve google.com: Unknown host
.
ping: cannot resolve google.com: Unknown host
.
ping: cannot resolve google.com: Unknown host
.
ping: cannot resolve google.com: Unknown host
.
PING google.com (172.217.4.78): 56 data bytes
64 bytes from 172.217.4.78: icmp_seq=0 ttl=49 time=47.809 ms
--- google.com ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 47.809/47.809/47.809/0.000 ms
.
Same code, modified to run in a plugin:
- Code: Select all
except requests.exceptions.ConnectionError:
while response != 0:
response = os.system("ping -c 1 google.com")
self.sleep(2)
indigo.server.log(u"{0}".format(response))
When Internet is removed, requests throws the exception and the while loop is called. However, when Internet is restored, the while loop is never broken, the ping response never reverts to 0 (zero) and instead just keeps reporting the non-zero number.
What am I missing?