Skip to content

Commit

Permalink
Move maybe_open_crash_handler() CLI --pdb-driven wrapper to debug…
Browse files Browse the repository at this point in the history
… mod
  • Loading branch information
goodboy committed Oct 2, 2023
1 parent 86da79a commit e94f126
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
2 changes: 2 additions & 0 deletions tractor/devx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
shield_sigint_handler,
MultiActorPdb,
open_crash_handler,
maybe_open_crash_handler,
post_mortem,
)

Expand All @@ -41,5 +42,6 @@
'shield_sigint_handler',
'MultiActorPdb',
'open_crash_handler',
'maybe_open_crash_handler',
'post_mortem',
]
18 changes: 18 additions & 0 deletions tractor/devx/_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from contextlib import (
asynccontextmanager as acm,
contextmanager as cm,
nullcontext,
)
from typing import (
Any,
Expand Down Expand Up @@ -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
13 changes: 0 additions & 13 deletions tractor/devx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from __future__ import annotations
from contextlib import (
# asynccontextmanager as acm,
nullcontext,
contextmanager as cm,
)
from typing import (
Expand Down Expand Up @@ -135,15 +134,3 @@ def my_cli_cmd(
)
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

0 comments on commit e94f126

Please sign in to comment.