From 1e73236ee8b5049ffb3fc5531adfc9ba79acd652 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Sat, 29 Apr 2023 09:40:09 -0500 Subject: [PATCH] Modified debug signal call setup --- src/app.py | 31 +++++-------------------------- src/utils/debugging.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 26 deletions(-) create mode 100644 src/utils/debugging.py diff --git a/src/app.py b/src/app.py index 1a5eae8..67b6211 100644 --- a/src/app.py +++ b/src/app.py @@ -5,34 +5,12 @@ import os # Lib imports # Application imports +from utils.debugging import debug_signal_handler from utils.ipc_server import IPCServer from core.window import Window -# Break into a Python console upon SIGUSR1 (Linux) or SIGBREAK (Windows: -# CTRL+Pause/Break). To be included in all production code, just in case. -def debug_signal_handler(signal, frame): - del signal - del frame - - try: - import rpdb2 - logger.debug("\n\nStarting embedded RPDB2 debugger. Password is 'foobar'\n\n") - rpdb2.start_embedded_debugger("foobar", True, True) - rpdb2.setbreak(depth=1) - return - except StandardError: - pass - - try: - import code - code.interact() - except StandardError as ex: - logger.debug(f"{ex}, returning to normal program flow...") - - - class AppLaunchException(Exception): ... @@ -58,10 +36,11 @@ class Application(IPCServer): raise AppLaunchException(f"{app_name} IPC Server Exists: Will send path(s) to it and close...") try: + # kill -SIGUSR2 from Linux/Unix or SIGBREAK signal from Windows signal.signal( - vars(signal).get("SIGBREAK") or vars(signal).get("SIGUSR1"), - debug_signal_handler - ) + vars(signal).get("SIGBREAK") or vars(signal).get("SIGUSR1"), + debug_signal_handler + ) except ValueError: # Typically: ValueError: signal only works in main thread ... diff --git a/src/utils/debugging.py b/src/utils/debugging.py new file mode 100644 index 0000000..97faff0 --- /dev/null +++ b/src/utils/debugging.py @@ -0,0 +1,35 @@ +# Python imports + +# Lib imports + +# Application imports + + + +# Break into a Python console upon SIGUSR1 (Linux) or SIGBREAK (Windows: +# CTRL+Pause/Break). To be included in all production code, just in case. +def debug_signal_handler(signal, frame): + del signal + del frame + + try: + import rpdb2 + logger.debug("\n\nStarting embedded RPDB2 debugger. Password is 'foobar'\n\n") + rpdb2.start_embedded_debugger("foobar", True, True) + rpdb2.setbreak(depth=1) + return + except StandardError: + pass + + try: + from rfoo.utils import rconsole + logger.debug("\n\nStarting embedded rconsole debugger...\n\n") + rconsole.spawn_server() + except StandardError as ex: + ... + + try: + import code + code.interact() + except StandardError as ex: + logger.debug(f"{ex}, returning to normal program flow...")