no traceback if computer has no local network
This commit is contained in:
parent
3ec134864b
commit
472d37dc01
1 changed files with 10 additions and 1 deletions
|
@ -46,6 +46,7 @@ def can_connect(data):
|
||||||
#logger.debug('failed to connect to local node %s', data, exc_info=1)
|
#logger.debug('failed to connect to local node %s', data, exc_info=1)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class LocalNodesBase(Thread):
|
class LocalNodesBase(Thread):
|
||||||
|
|
||||||
_PORT = 9851
|
_PORT = 9851
|
||||||
|
@ -99,10 +100,12 @@ class LocalNodesBase(Thread):
|
||||||
self.update_node(data)
|
self.update_node(data)
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
pass
|
pass
|
||||||
|
except OSError: # no local interface exists
|
||||||
|
self.wait(60)
|
||||||
except:
|
except:
|
||||||
if self._active:
|
if self._active:
|
||||||
logger.debug('receive failed. restart later', exc_info=1)
|
logger.debug('receive failed. restart later', exc_info=1)
|
||||||
time.sleep(10)
|
self.wait(60)
|
||||||
finally:
|
finally:
|
||||||
if self._active:
|
if self._active:
|
||||||
now = time.mktime(time.localtime())
|
now = time.mktime(time.localtime())
|
||||||
|
@ -166,6 +169,12 @@ class LocalNodesBase(Thread):
|
||||||
self._socket.close()
|
self._socket.close()
|
||||||
return Thread.join(self)
|
return Thread.join(self)
|
||||||
|
|
||||||
|
def wait(self, timeout):
|
||||||
|
step = min(timeout, 1)
|
||||||
|
while self._active and timeout > 0:
|
||||||
|
time.sleep(step)
|
||||||
|
timeout -= step
|
||||||
|
|
||||||
class LocalNodes4(LocalNodesBase):
|
class LocalNodes4(LocalNodesBase):
|
||||||
|
|
||||||
_BROADCAST = "239.255.255.250"
|
_BROADCAST = "239.255.255.250"
|
||||||
|
|
Loading…
Reference in a new issue