Move `maybe_open_crash_handler()` CLI `--pdb`-driven wrapper to debug mod

multihomed
Tyler Goodlet 2023-10-02 18:10:34 -04:00
parent 86da79a854
commit e94f1261b5
3 changed files with 20 additions and 13 deletions

View File

@ -29,6 +29,7 @@ from ._debug import (
shield_sigint_handler,
MultiActorPdb,
open_crash_handler,
maybe_open_crash_handler,
post_mortem,
)
@ -41,5 +42,6 @@ __all__ = [
'shield_sigint_handler',
'MultiActorPdb',
'open_crash_handler',
'maybe_open_crash_handler',
'post_mortem',
]

View File

@ -30,6 +30,7 @@ from functools import (
from contextlib import (
asynccontextmanager as acm,
contextmanager as cm,
nullcontext,
)
from typing import (
Any,
@ -1043,3 +1044,20 @@ def open_crash_handler(
except tuple(catch):
pdbp.xpm()
raise
@cm
def maybe_open_crash_handler(pdb: bool = False):
'''
Same as `open_crash_handler()` but with bool input flag
to allow conditional handling.
Normally this is used with CLI endpoints such that if the --pdb
flag is passed the pdb REPL is engaed on any crashes B)
'''
rtctx = nullcontext
if pdb:
rtctx = open_crash_handler
with rtctx():
yield

View File

@ -25,7 +25,6 @@ Currently popular frameworks supported are:
from __future__ import annotations
from contextlib import (
# asynccontextmanager as acm,
nullcontext,
contextmanager as cm,
)
from typing import (
@ -135,15 +134,3 @@ def load_runtime_vars(
)
ctx.params = {'ctx': ctx}
cmd.invoke(ctx)
@cm
def maybe_open_crash_handler(pdb: bool = False):
# if the --pdb flag is passed always engage
# the pdb REPL on any crashes B)
rtctx = nullcontext
if pdb:
rtctx = open_crash_handler
with rtctx():
yield