From 025cbe0db0120f5a003864cb1119d282d6405465 Mon Sep 17 00:00:00 2001 From: goodboy Date: Fri, 6 Nov 2026 11:17:53 -0500 Subject: [PATCH] Avoid boolean tests of debugger `trio.Event` handles On `trio` 0.34, boolean tests of `trio.Event` raise. Debugger setup/release, TTY-lock diagnostics and the RPC cancellation path used truthiness to check whether optional event handles existed, raising `NotImplementedError` instead of entering or leaving the REPL and waiting for its release. Use explicit `is None`/`is not None` checks for those five sites. Keep `.is_set()` for the actual release-state decision and retain the existing waits: an allocated pending event is not an absent handle, nor does its existence mean it has been signaled. Keep the debug-request comment beside its lock-release check. (this patch was generated in some part by `opencode` using `gpt-6.1-sol` (`openai`)) --- tractor/devx/debug/_trace.py | 4 ++-- tractor/devx/debug/_tty_lock.py | 5 +++-- tractor/runtime/_rpc.py | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tractor/devx/debug/_trace.py b/tractor/devx/debug/_trace.py index dc31fa92..970e127f 100644 --- a/tractor/devx/debug/_trace.py +++ b/tractor/devx/debug/_trace.py @@ -285,7 +285,7 @@ async def _pause( # the `PdbREPL`. repl_task: Thread|Task|None = DebugStatus.repl_task if ( - not DebugStatus.repl_release + DebugStatus.repl_release is None or DebugStatus.repl_release.is_set() ): @@ -849,7 +849,7 @@ async def _pause_from_bg_root_thread( stats: trio.LockStatistics= lock.statistics() assert stats.owner is task assert Lock._owned_by_root - assert DebugStatus.repl_release + assert DebugStatus.repl_release is not None # TODO: do we actually need this? # originally i was trying to solve wy this was diff --git a/tractor/devx/debug/_tty_lock.py b/tractor/devx/debug/_tty_lock.py index eae8c533..781a6cb8 100644 --- a/tractor/devx/debug/_tty_lock.py +++ b/tractor/devx/debug/_tty_lock.py @@ -172,7 +172,7 @@ class Lock: f'|_ .ctx_in_debug: {cls.ctx_in_debug}\n' f'|_ .req_handler_finished: {req}\n' ) - if req: + if req is not None: req_stats: trio.EventStatistics = req.statistics() fields += f' {req_stats}\n' @@ -288,7 +288,8 @@ class Lock: ) elif ( - req_handler_finished # new IPC ctx debug request active + # new IPC ctx debug request active + req_handler_finished is not None and lock.locked() # someone has the lock ): diff --git a/tractor/runtime/_rpc.py b/tractor/runtime/_rpc.py index 2f60c17b..e72ee1cf 100644 --- a/tractor/runtime/_rpc.py +++ b/tractor/runtime/_rpc.py @@ -1137,7 +1137,7 @@ async def process_messages( # runtime cancellation if this actor is # currently in debug mode! pdb_complete: trio.Event|None = debug.DebugStatus.repl_release - if pdb_complete: + if pdb_complete is not None: await pdb_complete.wait() # Either of `Actor.cancel()`/`.cancel_soon()`