From 2a7122d7fbd809e1586f7143ccfde3c0c061daf3 Mon Sep 17 00:00:00 2001 From: j Date: Sat, 7 Mar 2015 13:06:00 +0530 Subject: [PATCH] send local node announcement every 60 seconds --- oml/localnodes.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/oml/localnodes.py b/oml/localnodes.py index 56308fb..fa67abf 100644 --- a/oml/localnodes.py +++ b/oml/localnodes.py @@ -37,6 +37,7 @@ class LocalNodesBase(Thread): _PORT = 9851 _TTL = 1 + _TIMEOUT = 30 def __init__(self, nodes): self._socket = None @@ -74,6 +75,7 @@ class LocalNodesBase(Thread): while self._active: try: s = self.get_socket() + s.settimeout(self._TIMEOUT) s.bind(('', self._PORT)) while self._active: data, addr = s.recvfrom(1024) @@ -84,15 +86,17 @@ class LocalNodesBase(Thread): if data: self.update_node(data) except socket.timeout: + pass + except: + if self._active: + logger.debug('receive failed. restart later', exc_info=1) + time.sleep(10) + finally: if self._active: now = time.mktime(time.localtime()) if now - last > 60: last = now _thread.start_new_thread(self.send, ()) - except: - if self._active: - logger.debug('receive failed. restart later', exc_info=1) - time.sleep(10) def verify(self, data): try: