From af11eeecac8e6acee7eab56b48fc3e399095363b Mon Sep 17 00:00:00 2001 From: 1okko <15377594951@189.cn> Date: Wed, 21 Oct 2026 18:50:43 +0800 Subject: [PATCH] test: release SPI handle after panda enumeration --- panda/python/__init__.py | 10 ++++++---- panda/python/dfu.py | 10 +++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/panda/python/__init__.py b/panda/python/__init__.py index 9d562fc1e..004a1e003 100644 --- a/panda/python/__init__.py +++ b/panda/python/__init__.py @@ -345,10 +345,12 @@ class Panda: @classmethod def spi_list(cls): - _, _, serial, _ = cls.spi_connect(None) - if serial is not None: - return [serial, ] - return [] + _, handle, serial, _ = cls.spi_connect(None) + try: + return [serial, ] if serial is not None else [] + finally: + if handle is not None: + handle.close() def reset(self, enter_bootstub=False, enter_bootloader=False, reconnect=True): if enter_bootstub or enter_bootloader: diff --git a/panda/python/dfu.py b/panda/python/dfu.py index 624530cb2..1ee9821e9 100644 --- a/panda/python/dfu.py +++ b/panda/python/dfu.py @@ -87,13 +87,17 @@ class PandaDFU: @staticmethod def spi_list() -> list[str]: + handle = None try: - _, h = PandaDFU.spi_connect(None) - if h is not None: - dfu_serial = PandaDFU.st_serial_to_dfu_serial(h.get_uid(), h.get_mcu_type()) + _, handle = PandaDFU.spi_connect(None) + if handle is not None: + dfu_serial = PandaDFU.st_serial_to_dfu_serial(handle.get_uid(), handle.get_mcu_type()) return [dfu_serial, ] except PandaSpiException: pass + finally: + if handle is not None: + handle.close() return [] @staticmethod