fix localnodes

This commit is contained in:
j 2014-09-09 16:28:59 +02:00
parent 1e09e70574
commit 0956bd4966

View file

@ -74,12 +74,11 @@ 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)
if self._active: if self._active:
while data[-1] == '\0': while data[-1] == 0:
data = data[:-1] # Strip trailing \0's data = data[:-1] # Strip trailing \0's
data = self.verify(data) data = self.verify(data)
if data: if data:
@ -97,7 +96,7 @@ class LocalNodesBase(Thread):
def verify(self, data): def verify(self, data):
try: try:
packet = json.loads(data) packet = json.loads(data.decode())
except: except:
return None return None
if len(packet) == 3: if len(packet) == 3:
@ -149,7 +148,7 @@ class LocalNodesBase(Thread):
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)