From fbc5ab3eb6c58c016bad3815dc17923fdfa97403 Mon Sep 17 00:00:00 2001 From: richardsheridan Date: Wed, 25 Dec 2024 11:59:15 -0500 Subject: [PATCH] nit --- trio_parallel/_impl.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/trio_parallel/_impl.py b/trio_parallel/_impl.py index 6cb349b..59ce1a9 100644 --- a/trio_parallel/_impl.py +++ b/trio_parallel/_impl.py @@ -271,16 +271,10 @@ def configure_default_context( DEFAULT_CONTEXT = ctx -async def close_at_run_end(ctx): - try: - await trio.sleep_forever() - finally: - await ctx._aclose() # noqa: ASYNC102 - - CACHE_SCOPE_TREEVAR = tricycle.TreeVar("tp_cache_scope") + if sys.platform == "win32": - DEFAULT_CONTEXT_RUNVAR = trio.lowlevel.RunVar("win32_ctx") + DEFAULT_CONTEXT_RUNVAR = trio.lowlevel.RunVar("tp_win32_ctx") DEFAULT_CONTEXT_PARAMS = {} def get_default_context(): @@ -297,6 +291,12 @@ def get_default_context(): DEFAULT_CONTEXT_RUNVAR.set(ctx) return ctx + async def close_at_run_end(ctx): + try: + await trio.sleep_forever() + finally: + await ctx._aclose() # noqa: ASYNC102 + else: def get_default_context(): @@ -390,7 +390,8 @@ async def cache_scope( worker_type=WorkerType.SPAWN, ): """ - Override the configuration of `trio_parallel.run_sync()` in this and all subtasks. + Override the configuration of `trio_parallel.run_sync()` in this task and all + subtasks. The context will automatically wait for any running workers to become idle when exiting the scope. Since this wait cannot be cancelled, it is more convenient to