forked from goodboy/tractor
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,
|
shield_sigint_handler,
|
||||||
MultiActorPdb,
|
MultiActorPdb,
|
||||||
open_crash_handler,
|
open_crash_handler,
|
||||||
|
maybe_open_crash_handler,
|
||||||
post_mortem,
|
post_mortem,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -41,5 +42,6 @@ __all__ = [
|
||||||
'shield_sigint_handler',
|
'shield_sigint_handler',
|
||||||
'MultiActorPdb',
|
'MultiActorPdb',
|
||||||
'open_crash_handler',
|
'open_crash_handler',
|
||||||
|
'maybe_open_crash_handler',
|
||||||
'post_mortem',
|
'post_mortem',
|
||||||
]
|
]
|
||||||
|
|
|
@ -30,6 +30,7 @@ from functools import (
|
||||||
from contextlib import (
|
from contextlib import (
|
||||||
asynccontextmanager as acm,
|
asynccontextmanager as acm,
|
||||||
contextmanager as cm,
|
contextmanager as cm,
|
||||||
|
nullcontext,
|
||||||
)
|
)
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
|
@ -1043,3 +1044,20 @@ def open_crash_handler(
|
||||||
except tuple(catch):
|
except tuple(catch):
|
||||||
pdbp.xpm()
|
pdbp.xpm()
|
||||||
raise
|
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 __future__ import annotations
|
||||||
from contextlib import (
|
from contextlib import (
|
||||||
# asynccontextmanager as acm,
|
# asynccontextmanager as acm,
|
||||||
nullcontext,
|
|
||||||
contextmanager as cm,
|
contextmanager as cm,
|
||||||
)
|
)
|
||||||
from typing import (
|
from typing import (
|
||||||
|
@ -135,15 +134,3 @@ def load_runtime_vars(
|
||||||
)
|
)
|
||||||
ctx.params = {'ctx': ctx}
|
ctx.params = {'ctx': ctx}
|
||||||
cmd.invoke(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