better shutdown
This commit is contained in:
parent
88a5ed9edc
commit
417d02bdd4
1 changed files with 9 additions and 10 deletions
|
@ -59,14 +59,12 @@ class LocalNodesBase(Thread):
|
||||||
|
|
||||||
def join(self):
|
def join(self):
|
||||||
self._active = False
|
self._active = False
|
||||||
'''
|
|
||||||
if self._socket:
|
if self._socket:
|
||||||
try:
|
try:
|
||||||
self._socket.shutdown(socket.SHUT_RDWR)
|
self._socket.shutdown(socket.SHUT_RDWR)
|
||||||
except:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
self._socket.close()
|
self._socket.close()
|
||||||
'''
|
|
||||||
return Thread.join(self)
|
return Thread.join(self)
|
||||||
|
|
||||||
def new_node(self, data):
|
def new_node(self, data):
|
||||||
|
@ -80,7 +78,6 @@ class LocalNodesBase(Thread):
|
||||||
while self._active:
|
while self._active:
|
||||||
try:
|
try:
|
||||||
s = self.get_socket()
|
s = self.get_socket()
|
||||||
s.settimeout(2)
|
|
||||||
s.bind(('', self._PORT))
|
s.bind(('', self._PORT))
|
||||||
while self._active:
|
while self._active:
|
||||||
data, addr = s.recvfrom(1024)
|
data, addr = s.recvfrom(1024)
|
||||||
|
@ -91,11 +88,13 @@ class LocalNodesBase(Thread):
|
||||||
if data:
|
if data:
|
||||||
self.update_node(data)
|
self.update_node(data)
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
|
if self._active:
|
||||||
now = time.mktime(time.localtime())
|
now = time.mktime(time.localtime())
|
||||||
if now - last > 60:
|
if now - last > 60:
|
||||||
last = now
|
last = now
|
||||||
_thread.start_new_thread(self.send, ())
|
_thread.start_new_thread(self.send, ())
|
||||||
except:
|
except:
|
||||||
|
if self._active:
|
||||||
logger.debug('receive failed. restart later', exc_info=1)
|
logger.debug('receive failed. restart later', exc_info=1)
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue