stratified_packager.toolbelt.debugging
Optional debugpy bootstrap for attaching an IDE to the (possibly embedded) Python.
start_debug_server() opens a debugpy listen
socket when the QGIS_DEBUGPY environment variable is truthy, so an IDE can attach to
the running interpreter; it is a no-op otherwise, which keeps it dormant in normal use while
costing nothing to leave wired in.
When Python is embedded in a host application — QGIS runs the interpreter inside its qgis
/ qgis_process executable — sys.executable points at that host binary rather than
at Python. Since debugpy needs the real interpreter to spawn its adapter subprocess, the
bootstrap resolves it with python_executable() and
passes it to debugpy.configure before listening.
Recognised environment variables (explicit host / port arguments take precedence),
read through the typed EnvironmentVariables
subclass _DebugEnv:
- QGIS_DEBUGPY
Truthy (
1/true/yes/on) to enable the listen server.
- QGIS_DEBUGPY_HOST
Host/address to listen on (default
"localhost").
- QGIS_DEBUGPY_PORT
TCP port to listen on (default
5678).
- QGIS_DEBUGPY_WAIT
Truthy to block startup until an IDE attaches — needed to break on early load (e.g.
classFactory/initGui) or on a short-livedqgis_processrun.
debugpy is an optional dependency imported lazily inside start_debug_server();
when it is not installed the resulting ImportError is contained like any other failure,
so the bootstrap never breaks loading.
Functions
|
Start a debugpy listen server when |
- class stratified_packager.toolbelt.debugging._DebugEnv(environ=None)[source]
Typed view of the
QGIS_DEBUGPY*environment toggles (see the module docstring).- Parameters:
environ (
MutableMapping[str,str] |None)
- _abc_impl = <_abc._abc_data object>
- stratified_packager.toolbelt.debugging.start_debug_server(host=None, port=None)[source]
Start a debugpy listen server when
QGIS_DEBUGPYis truthy, else do nothing.Resolve the listen address from the arguments, then the
QGIS_DEBUGPY*environment variables, then the module defaults. Safe to call on every plugin load: a repeat call, a missingdebugpyor a busy port is logged and swallowed so that loading never fails because of the debugger.- Parameters:
host (
str|None) – Host/address to listen on; overridesQGIS_DEBUGPY_HOST.port (
int|None) – TCP port to listen on; overridesQGIS_DEBUGPY_PORT.
- Return type:
- Returns:
Truewhen the server is (already) listening,Falseotherwise.