Fix threading

This commit is contained in:
Joscha 2016-05-23 16:24:17 +02:00
parent e332053380
commit fbd7360914

View file

@ -93,7 +93,8 @@ class Connection():
""" """
if self._connect(tries=1): if self._connect(tries=1):
self._thread = threading.Thread(target=self._run, name=self.room) self._thread = threading.Thread(target=self._run,
name="{}-{}".format(self.room, int(time.time())))
self._thread.start() self._thread.start()
return self._thread return self._thread
else: else:
@ -109,7 +110,7 @@ class Connection():
while not self._stopping: while not self._stopping:
try: try:
self._handle_json(self._ws.recv()) self._handle_json(self._ws.recv())
except WSException: except (WSException, ConnectionResetError):
if not self._stopping: if not self._stopping:
self.disconnect() self.disconnect()
self._connect() self._connect()
@ -127,7 +128,7 @@ class Connection():
self._callbacks.call("stop") self._callbacks.call("stop")
if self._thread: if self._thread and self._thread != threading.current_thread():
self._thread.join() self._thread.join()
def next_id(self): def next_id(self):