From 417d02bdd4a69221752784999d27d83b94e9faf9 Mon Sep 17 00:00:00 2001 From: j Date: Tue, 9 Sep 2014 15:07:33 +0200 Subject: [PATCH] better shutdown --- peerlink/localnodes.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/peerlink/localnodes.py b/peerlink/localnodes.py index 3078359..440618e 100644 --- a/peerlink/localnodes.py +++ b/peerlink/localnodes.py @@ -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()