Like this:
import urllib2,thread
from time import sleep
import netifaces
class _check:
def __init__(self):
self.uri="http://www.google.com"
self.period = 5
self.status = False
self.ifaces()
def check(self):
try:
answ = urllib2.urlopen(self.uri)
if answ:
self.status = True
print "okay go take a beer"
except Exception,e : print e
def timer(self,pass_arg) :
while True :
if self.status != True :
self.check()
sleep(self.period)
print "running"
elif self.status == True :
print "thread ending"
break
def ifaces(self):
for i in netifaces.interfaces() :
try:
print i,netifaces.ifaddresses(i)[2]
except:
print i, "iface not up !"
check = _check()
thread.start_new_thread(check.timer,(None,))
so that this answer matches my comment.
source
share