From c99bb1f104a0f5a04c1b6e926001df8c6c0ba681 Mon Sep 17 00:00:00 2001 From: Daniel Gretzke Date: Tue, 10 Dec 2019 18:05:02 +0100 Subject: [PATCH] added more exception logging --- plug_py/plug.py | 19 ++++++++++++++++--- socket_py/socket_py.py | 27 ++++++++++++--------------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/plug_py/plug.py b/plug_py/plug.py index 5d4a288..14d870d 100644 --- a/plug_py/plug.py +++ b/plug_py/plug.py @@ -344,7 +344,8 @@ def run(self): except timeout: window.updateInfo('No smart socket found') window.updateInfoCenter('') - except: + except Exception as e: + print(e) window.resetToStart() window.updateInfo('An error occurred') @@ -373,6 +374,9 @@ async def receiveMessage(self): except asyncio.TimeoutError: # no new message pass + except Exception as e: + print(e) + raise e # received message if message != None: @@ -380,10 +384,12 @@ async def receiveMessage(self): # parse JSON of message parsedMessage = json.loads(message) print(parsedMessage) - except JSONDecodeError: print('Received message could not be parsed: ' + message) pass + except Exception as e: + print(e) + raise e # execute code according to states if parsedMessage['id'] == State.connected_S.value: @@ -451,6 +457,9 @@ async def connected_S(self, parsedMessage): transactionHash) except TransactionNotFound: pass + except Exception as e: + print(e) + raise e QThread.sleep(1) if (transactionReceipt.status != 1): @@ -537,6 +546,9 @@ async def initialized_P(self): transactionHash) except TransactionNotFound: pass + except Exception as e: + print(e) + raise e await asyncio.sleep(1) if (transactionReceipt.status == 1): @@ -634,7 +646,8 @@ async def wsConnection(self): try: # wait until connected to websocket self.websocket = await websockets.connect(self.IP) - except: + except Exception as e: + print(e) # if connection times out close thread window.ui.startButton.setVisible(True) window.updateInfoCenter('') diff --git a/socket_py/socket_py.py b/socket_py/socket_py.py index ce6ee12..7b6b3fa 100644 --- a/socket_py/socket_py.py +++ b/socket_py/socket_py.py @@ -118,19 +118,6 @@ def closeEvent(self, event): # GPIO.cleanup() event.accept() # let the window close - def terminateThread(self, process): - try: - thread = operator.attrgetter(process)(self) - if thread.threadActive: - thread.threadActive = False - thread.quit() - if (thread.wait(1000) == False): - thread.terminate() - thread.wait() - except AttributeError: - # thread was not created yet - pass - def updateInfoCenter(self, str): if (str == ''): self.ui.infoCenterLabel.setVisible(False) @@ -292,7 +279,9 @@ async def wsServer(self, websocket, path): elif self.paymentState == State.closed: await self.closed() - + except Exception as e: + print(e) + raise e finally: self.websocket = None self.connected.remove(websocket) @@ -309,6 +298,9 @@ async def receiveMessage(self): except asyncio.TimeoutError: # no new message pass + except Exception as e: + print(e) + raise e # received message if message != None: @@ -316,10 +308,12 @@ async def receiveMessage(self): # parse JSON of message parsedMessage = json.loads(message) print(parsedMessage) - except JSONDecodeError: print('Received message could not be parsed: ' + message) pass + except Exception as e: + print(e) + raise e # execute code according to states if parsedMessage['id'] == State.connected_P.value: @@ -436,6 +430,9 @@ async def closed(self): transactionHash) except TransactionNotFound: pass + except Exception as e: + print(e) + raise e QThread.sleep(1) window.updateInfoCenter('Successfully closed\nPayment Channel')