From 312c77629b711b88366c5a122278820e3c349c85 Mon Sep 17 00:00:00 2001 From: Alexander Hirsch Date: Mon, 3 Jun 2019 16:08:28 -0700 Subject: [PATCH 1/3] Provides debuging option for TCP stream The TCP BaseClient class has been modified to recognize an environment variable 'PYMODES_DEBUG'. When the variable is set to 'true', the stream will halt execution rather than restarting. This is for debugging purposes and does not alter the main functionality of the program. --- pyModeS/extra/tcpclient.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pyModeS/extra/tcpclient.py b/pyModeS/extra/tcpclient.py index 22539b6..adc428f 100644 --- a/pyModeS/extra/tcpclient.py +++ b/pyModeS/extra/tcpclient.py @@ -269,7 +269,16 @@ class BaseClient(Thread): time.sleep(0.001) except Exception as e: - print("Unexpected Error:", e) + + # Provides the user an option to supply the environment + # variable PYMODES_DEBUG to halt the execution + # for debugging purposes + debug_intent = os.environ.get('PYMODES_DEBUG', None) + if debug_intent.lower() == 'true': + sys.exc_info() + sys.exit() + else: + print("Unexpected Error:", e) try: sock = self.connect() From 0ea4969393c72ebfb904f825e3f0d003b80a427c Mon Sep 17 00:00:00 2001 From: Alexander Hirsch Date: Mon, 3 Jun 2019 17:23:26 -0700 Subject: [PATCH 2/3] Print the traceback of TCP client Exception The function now prints the system execution information upon an exception. The last commit requested traceback information, but did not print the information to the console. --- pyModeS/extra/tcpclient.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyModeS/extra/tcpclient.py b/pyModeS/extra/tcpclient.py index adc428f..8969f9c 100644 --- a/pyModeS/extra/tcpclient.py +++ b/pyModeS/extra/tcpclient.py @@ -275,7 +275,7 @@ class BaseClient(Thread): # for debugging purposes debug_intent = os.environ.get('PYMODES_DEBUG', None) if debug_intent.lower() == 'true': - sys.exc_info() + print(sys.exc_info()) sys.exit() else: print("Unexpected Error:", e) From 9f371fe86b6483d1d60fc67aa6d74436bcf4a6f8 Mon Sep 17 00:00:00 2001 From: Alexander Hirsch Date: Mon, 3 Jun 2019 17:42:26 -0700 Subject: [PATCH 3/3] Stream errors are printed with full traceback The stream will now properly print the traceback of an error if the debuging variable is set. --- pyModeS/extra/tcpclient.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyModeS/extra/tcpclient.py b/pyModeS/extra/tcpclient.py index 8969f9c..e8d15d0 100644 --- a/pyModeS/extra/tcpclient.py +++ b/pyModeS/extra/tcpclient.py @@ -7,6 +7,7 @@ import sys import socket import time from threading import Thread +import traceback if (sys.version_info > (3, 0)): PY_VERSION = 3 @@ -275,7 +276,7 @@ class BaseClient(Thread): # for debugging purposes debug_intent = os.environ.get('PYMODES_DEBUG', None) if debug_intent.lower() == 'true': - print(sys.exc_info()) + traceback.print_exc() sys.exit() else: print("Unexpected Error:", e)