From 629e070412575a235b90fccabeac2313bb282d56 Mon Sep 17 00:00:00 2001 From: ChaoZheng109 Date: Tue, 30 Jun 2026 21:02:36 +0800 Subject: [PATCH] Fix: release _ChipWorker handle in Worker.close() L2 branch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The L2 teardown branch called self._chip_worker.finalize() but never dropped the Python reference, so the _ChipWorker nanobind instance stayed alive on the closed Worker. This is inconsistent with the L>=3 branch (self._worker = None) and the error path (self._chip_worker = None). When a pytest case fails, pytest retains its traceback, which pins the failing frame's worker local and through it the _ChipWorker instance until interpreter exit — where nanobind's leak check fires and dumps the "leaked instance ... _ChipWorker" / leaked types / leaked functions warning. Dropping the handle on close releases the instance so it no longer outlives the module. Closes #1221 --- python/simpler/worker.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/simpler/worker.py b/python/simpler/worker.py index 3b7b92c3e..13cb56ab9 100644 --- a/python/simpler/worker.py +++ b/python/simpler/worker.py @@ -3915,6 +3915,7 @@ def close(self) -> None: # noqa: PLR0912 -- parallel teardown for _worker + sub if self.level == 2: if self._chip_worker: self._chip_worker.finalize() + self._chip_worker = None else: if self._worker: self._worker.close()