Skip to content

Commit

Permalink
Add debug_mode: bool control to task mngr
Browse files Browse the repository at this point in the history
  • Loading branch information
goodboy committed May 19, 2023
1 parent e0c888f commit 872dcd7
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions tractor/trionics/_supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
asynccontextmanager as acm,
contextmanager as cm,
)
from functools import partial
from typing import (
Generator,
Any,
Expand Down Expand Up @@ -206,6 +207,8 @@ async def _start_wrapped_in_scope(
def add_task_handle_and_crash_handling(
nursery: Nursery,

debug_mode: bool = False,

) -> Generator[
Any,
Outcome,
Expand Down Expand Up @@ -246,7 +249,8 @@ def add_task_handle_and_crash_handling(
# a REPL on std errors.
except Exception as err:
print(f'{task.name} crashed, entering debugger!')
pdbp.xpm()
if debug_mode:
pdbp.xpm()
raise

finally:
Expand All @@ -255,11 +259,15 @@ def add_task_handle_and_crash_handling(

@acm
async def open_nursery(
task_manager = None,
**kwargs,
task_manager: Generator[Any, Outcome, None] | None = None,

**lowlevel_nursery_kwargs,
):
async with trio.open_nursery(**kwargs) as nurse:
yield TaskManagerNursery(nurse, task_manager=task_manager)
async with trio.open_nursery(**lowlevel_nursery_kwargs) as nurse:
yield TaskManagerNursery(
nurse,
task_manager=task_manager,
)


async def sleep_then_return_val(val: str):
Expand All @@ -284,7 +292,10 @@ async def ensure_cancelled():

async def main():
async with open_nursery(
task_manager=add_task_handle_and_crash_handling,
task_manager=partial(
add_task_handle_and_crash_handling,
debug_mode=True,
),
) as sn:
for _ in range(3):
outcome, _ = await sn.start_soon(trio.sleep_forever)
Expand Down

0 comments on commit 872dcd7

Please sign in to comment.