mirror of
https://github.com/BOSWatch/BW3-Core.git
synced 2026-01-04 15:49:57 +01:00
some improvements
This commit is contained in:
parent
1837ba46af
commit
71065672a7
|
|
@ -30,6 +30,8 @@ class NetCheck:
|
||||||
@param timout: timout for connection check in sec. (1)"""
|
@param timout: timout for connection check in sec. (1)"""
|
||||||
self._hostname = hostname
|
self._hostname = hostname
|
||||||
self._timeout = timeout
|
self._timeout = timeout
|
||||||
|
self._connectionState = False
|
||||||
|
self.checkConn() # initiate a first check
|
||||||
|
|
||||||
def checkConn(self):
|
def checkConn(self):
|
||||||
"""!Check the connection
|
"""!Check the connection
|
||||||
|
|
@ -38,7 +40,14 @@ class NetCheck:
|
||||||
try:
|
try:
|
||||||
urlopen(self._hostname, timeout=self._timeout)
|
urlopen(self._hostname, timeout=self._timeout)
|
||||||
logging.debug("%s is reachable", self._hostname)
|
logging.debug("%s is reachable", self._hostname)
|
||||||
|
self._connectionState = True
|
||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
logging.warning("%s is not reachable", self._hostname)
|
logging.warning("%s is not reachable", self._hostname)
|
||||||
|
self._connectionState = False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def connectionState(self):
|
||||||
|
"""!Property for the last connection state from checkConn()"""
|
||||||
|
return self._connectionState
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,8 @@ class RepeatedTimer:
|
||||||
else:
|
else:
|
||||||
logging.warning("timer overdue! interval: %0.3f sec. - runtime: %0.3f sec.", self._interval, runTime)
|
logging.warning("timer overdue! interval: %0.3f sec. - runtime: %0.3f sec.", self._interval, runTime)
|
||||||
self._overdueCount += 1
|
self._overdueCount += 1
|
||||||
|
logging.debug("repeatedTimer thread stopped: %s", self._thread.name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def restTime(self):
|
def restTime(self):
|
||||||
"""!Property to get remaining time till next call"""
|
"""!Property to get remaining time till next call"""
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,11 @@ except Exception as e: # pragma: no cover
|
||||||
from boswatch.utils.timer import RepeatedTimer
|
from boswatch.utils.timer import RepeatedTimer
|
||||||
from boswatch.network.netCheck import NetCheck
|
from boswatch.network.netCheck import NetCheck
|
||||||
net = NetCheck()
|
net = NetCheck()
|
||||||
test = RepeatedTimer(10, net.checkConn)
|
test = RepeatedTimer(3, net.checkConn)
|
||||||
test.start()
|
test.start()
|
||||||
|
time.sleep(10)
|
||||||
|
print(net.connectionState)
|
||||||
|
test.stop()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
header.logoToLog()
|
header.logoToLog()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue