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):
|
||||
self._active = False
|
||||
'''
|
||||
if self._socket:
|
||||
try:
|
||||
self._socket.shutdown(socket.SHUT_RDWR)
|
||||
except:
|
||||
except OSError:
|
||||
pass
|
||||
self._socket.close()
|
||||
'''
|
||||
return Thread.join(self)
|
||||
|
||||
def new_node(self, data):
|
||||
|
@ -80,7 +78,6 @@ class LocalNodesBase(Thread):
|
|||
while self._active:
|
||||
try:
|
||||
s = self.get_socket()
|
||||
s.settimeout(2)
|
||||
s.bind(('', self._PORT))
|
||||
while self._active:
|
||||
data, addr = s.recvfrom(1024)
|
||||
|
@ -91,13 +88,15 @@ class LocalNodesBase(Thread):
|
|||
if data:
|
||||
self.update_node(data)
|
||||
except socket.timeout:
|
||||
now = time.mktime(time.localtime())
|
||||
if now - last > 60:
|
||||
last = now
|
||||
_thread.start_new_thread(self.send, ())
|
||||
if self._active:
|
||||
now = time.mktime(time.localtime())
|
||||
if now - last > 60:
|
||||
last = now
|
||||
_thread.start_new_thread(self.send, ())
|
||||
except:
|
||||
logger.debug('receive failed. restart later', exc_info=1)
|
||||
time.sleep(10)
|
||||
if self._active:
|
||||
logger.debug('receive failed. restart later', exc_info=1)
|
||||
time.sleep(10)
|
||||
|
||||
def run(self):
|
||||
self.send()
|
||||
|
|
Loading…
Reference in a new issue