added debugging control interupt
This commit is contained in:
parent
f0784916ed
commit
e51f706462
12
src/app.py
12
src/app.py
|
@ -1,9 +1,11 @@
|
||||||
# Python imports
|
# Python imports
|
||||||
|
import signal
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# Lib imports
|
# Lib imports
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
|
from utils.debugging import debug_signal_handler
|
||||||
from utils.ipc_server import IPCServer
|
from utils.ipc_server import IPCServer
|
||||||
from core.window import Window
|
from core.window import Window
|
||||||
|
|
||||||
|
@ -34,4 +36,14 @@ class Application(IPCServer):
|
||||||
|
|
||||||
raise AppLaunchException(f"{app_name} IPC Server Exists: Will send path(s) to it and close...")
|
raise AppLaunchException(f"{app_name} IPC Server Exists: Will send path(s) to it and close...")
|
||||||
|
|
||||||
|
try:
|
||||||
|
# kill -SIGUSR2 <pid> from Linux/Unix or SIGBREAK signal from Windows
|
||||||
|
signal.signal(
|
||||||
|
vars(signal).get("SIGBREAK") or vars(signal).get("SIGUSR1"),
|
||||||
|
debug_signal_handler
|
||||||
|
)
|
||||||
|
except ValueError:
|
||||||
|
# Typically: ValueError: signal only works in main thread
|
||||||
|
...
|
||||||
|
|
||||||
Window(args, unknownargs)
|
Window(args, unknownargs)
|
||||||
|
|
|
@ -38,7 +38,7 @@ class Window(Gtk.ApplicationWindow):
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
# NOTE: Need to set size after show b/c get_allocation methods are initially incorrect if done beforehand...
|
# NOTE: Need to set size after show b/c get_allocation methods are initially incorrect if done beforehand...
|
||||||
self.set_given_size()
|
self._set_size_constraints()
|
||||||
|
|
||||||
|
|
||||||
def _setup_styling(self):
|
def _setup_styling(self):
|
||||||
|
@ -47,10 +47,11 @@ class Window(Gtk.ApplicationWindow):
|
||||||
self.set_gravity(5) # 5 = CENTER
|
self.set_gravity(5) # 5 = CENTER
|
||||||
self.set_position(1) # 1 = CENTER, 4 = CENTER_ALWAYS
|
self.set_position(1) # 1 = CENTER, 4 = CENTER_ALWAYS
|
||||||
|
|
||||||
def set_given_size(self):
|
def _set_size_constraints(self):
|
||||||
self.set_default_size(settings.get_main_window_width(),
|
self.set_default_size(settings.get_main_window_width(),
|
||||||
settings.get_main_window_height())
|
settings.get_main_window_height())
|
||||||
self.set_size_request(720, 480)
|
self.set_size_request(settings.get_main_window_min_width(),
|
||||||
|
settings.get_main_window_min_height())
|
||||||
|
|
||||||
def _setup_signals(self):
|
def _setup_signals(self):
|
||||||
self.connect("delete-event", self._tear_down)
|
self.connect("delete-event", self._tear_down)
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
# 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:
|
||||||
|
...
|
||||||
|
|
||||||
|
try:
|
||||||
|
from rfoo.utils import rconsole
|
||||||
|
logger.debug("\n\nStarting embedded rconsole debugger...\n\n")
|
||||||
|
rconsole.spawn_server()
|
||||||
|
return
|
||||||
|
except StandardError as ex:
|
||||||
|
...
|
||||||
|
|
||||||
|
try:
|
||||||
|
from pudb import set_trace
|
||||||
|
logger.debug("\n\nStarting PuDB debugger...\n\n")
|
||||||
|
set_trace(paused = True)
|
||||||
|
return
|
||||||
|
except StandardError as ex:
|
||||||
|
...
|
||||||
|
|
||||||
|
try:
|
||||||
|
import pdb
|
||||||
|
logger.debug("\n\nStarting embedded PDB debugger...\n\n")
|
||||||
|
pdb.Pdb(skip=['gi.*']).set_trace()
|
||||||
|
return
|
||||||
|
except StandardError as ex:
|
||||||
|
...
|
||||||
|
|
||||||
|
try:
|
||||||
|
import code
|
||||||
|
code.interact()
|
||||||
|
except StandardError as ex:
|
||||||
|
logger.debug(f"{ex}, returning to normal program flow...")
|
|
@ -88,15 +88,17 @@ class Settings(StartCheckMixin, Singleton):
|
||||||
print( f"Settings: {self._CONTEXT_MENU}\n\t\t{repr(e)}" )
|
print( f"Settings: {self._CONTEXT_MENU}\n\t\t{repr(e)}" )
|
||||||
|
|
||||||
|
|
||||||
self._main_window = None
|
self._main_window = None
|
||||||
self._main_window_w = 800
|
self._main_window_w = 800
|
||||||
self._main_window_h = 600
|
self._main_window_h = 600
|
||||||
self._builder = None
|
self._main_window_mw = 720
|
||||||
self.PAINT_BG_COLOR = (0, 0, 0, 0.54)
|
self._main_window_mh = 480
|
||||||
|
self._builder = None
|
||||||
|
self.PAINT_BG_COLOR = (0, 0, 0, 0.54)
|
||||||
|
|
||||||
self._trace_debug = False
|
self._trace_debug = False
|
||||||
self._debug = False
|
self._debug = False
|
||||||
self._dirty_start = False
|
self._dirty_start = False
|
||||||
|
|
||||||
self.load_settings()
|
self.load_settings()
|
||||||
|
|
||||||
|
@ -130,6 +132,8 @@ class Settings(StartCheckMixin, Singleton):
|
||||||
def get_main_window(self) -> any: return self._main_window
|
def get_main_window(self) -> any: return self._main_window
|
||||||
def get_main_window_width(self) -> any: return self._main_window_w
|
def get_main_window_width(self) -> any: return self._main_window_w
|
||||||
def get_main_window_height(self) -> any: return self._main_window_h
|
def get_main_window_height(self) -> any: return self._main_window_h
|
||||||
|
def get_main_window_min_width(self) -> any: return self._main_window_mw
|
||||||
|
def get_main_window_min_height(self) -> any: return self._main_window_mh
|
||||||
def get_builder(self) -> any: return self._builder
|
def get_builder(self) -> any: return self._builder
|
||||||
def get_paint_bg_color(self) -> any: return self.PAINT_BG_COLOR
|
def get_paint_bg_color(self) -> any: return self.PAINT_BG_COLOR
|
||||||
def get_glade_file(self) -> str: return self._GLADE_FILE
|
def get_glade_file(self) -> str: return self._GLADE_FILE
|
||||||
|
|
|
@ -41,6 +41,7 @@ class StartCheckMixin:
|
||||||
def _write_new_pid(self):
|
def _write_new_pid(self):
|
||||||
pid = os.getpid()
|
pid = os.getpid()
|
||||||
self._write_pid(pid)
|
self._write_pid(pid)
|
||||||
|
print(f"{app_name} PID: {pid}")
|
||||||
|
|
||||||
def _clean_pid(self):
|
def _clean_pid(self):
|
||||||
os.unlink(self._PID_FILE)
|
os.unlink(self._PID_FILE)
|
||||||
|
|
Loading…
Reference in New Issue