From b24f0d5c1eb3b2ea7c7d76d9a9ec759770037d32 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 19 May 2023 14:49:10 -0400 Subject: [PATCH] Go all in on "task manager" naming --- tractor/trionics/_supervisor.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tractor/trionics/_supervisor.py b/tractor/trionics/_supervisor.py index 46a1ccdf..3a2f176f 100644 --- a/tractor/trionics/_supervisor.py +++ b/tractor/trionics/_supervisor.py @@ -102,14 +102,14 @@ async def wait_for_result(self) -> Any: return self.result -class ScopePerTaskNursery(Struct): +class TaskManagerNursery(Struct): _n: Nursery _scopes: dict[ Task, tuple[CancelScope, Outcome] ] = {} - scope_manager: Generator[Any, Outcome, None] | None = None + task_manager: Generator[Any, Outcome, None] | None = None async def start_soon( self, @@ -117,7 +117,7 @@ async def start_soon( *args, name=None, - scope_manager: ContextManager | None = None, + task_manager: Generator[Any, Outcome, None] | None = None ) -> tuple[CancelScope, Task]: @@ -131,7 +131,7 @@ async def start_soon( n: Nursery = self._n - sm = self.scope_manager + sm = self.task_manager # we do default behavior of a scope-per-nursery # if the user did not provide a task manager. if sm is None: @@ -261,14 +261,11 @@ def add_task_handle_and_crash_handling( @acm async def open_nursery( - scope_manager = None, + task_manager = None, **kwargs, ): async with trio.open_nursery(**kwargs) as nurse: - yield ScopePerTaskNursery( - nurse, - scope_manager=scope_manager, - ) + yield TaskManagerNursery(nurse, task_manager=task_manager) async def sleep_then_return_val(val: str): @@ -293,7 +290,7 @@ async def ensure_cancelled(): async def main(): async with open_nursery( - scope_manager=add_task_handle_and_crash_handling, + task_manager=add_task_handle_and_crash_handling, ) as sn: for _ in range(3): outcome, _ = await sn.start_soon(trio.sleep_forever) @@ -312,7 +309,7 @@ async def main(): await trio.sleep(0.6) print( - 'Cancelling and waiting on {err_outcome.lowlevel_task} ' + f'Cancelling and waiting on {err_outcome.lowlevel_task} ' 'to CRASH..' ) cs.cancel()