Modified debug signal call setup
This commit is contained in:
		
							
								
								
									
										31
									
								
								src/app.py
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								src/app.py
									
									
									
									
									
								
							| @@ -5,34 +5,12 @@ 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 | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| # 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): | 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...") |                 raise AppLaunchException(f"{app_name} IPC Server Exists: Will send path(s) to it and close...") | ||||||
|  |  | ||||||
|         try: |         try: | ||||||
|  |             # kill -SIGUSR2 <pid> from Linux/Unix or SIGBREAK signal from Windows | ||||||
|             signal.signal( |             signal.signal( | ||||||
|                     vars(signal).get("SIGBREAK") or vars(signal).get("SIGUSR1"), |                 vars(signal).get("SIGBREAK") or vars(signal).get("SIGUSR1"), | ||||||
|                     debug_signal_handler |                 debug_signal_handler | ||||||
|                     ) |             ) | ||||||
|         except ValueError: |         except ValueError: | ||||||
|             # Typically: ValueError: signal only works in main thread |             # Typically: ValueError: signal only works in main thread | ||||||
|             ... |             ... | ||||||
|   | |||||||
							
								
								
									
										35
									
								
								src/utils/debugging.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/utils/debugging.py
									
									
									
									
									
										Normal file
									
								
							| @@ -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...") | ||||||
		Reference in New Issue
	
	Block a user