Move `maybe_open_crash_handler()` CLI `--pdb`-driven wrapper to debug mod
parent
86da79a854
commit
e94f1261b5
|
@ -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',
|
||||
]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue