Skip to content

Commit 4367d90

Browse files
CopilotBenGardiner
andcommitted
Fix gs_usb shutdown to always call parent BusABC.shutdown()
BusABC has a class-level _is_shutdown = True attribute. When __init__ was not called (as in test mocks), GsUsbBus.shutdown() resolved this class attribute and returned early, never calling super().shutdown(). Restructure shutdown() to always call super().shutdown(), using the pre-call _is_shutdown state only to guard interface-specific cleanup. Co-authored-by: BenGardiner <243321+BenGardiner@users.noreply.github.com>
1 parent f0cbee0 commit 4367d90

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

can/interfaces/gs_usb.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def __init__(
6868
:param can_filters: not supported
6969
:param bitrate: CAN network bandwidth (bits/s)
7070
"""
71-
self._is_shutdown = False
7271
if (index is not None) and ((bus or address) is not None):
7372
raise CanInitializationError(
7473
"index and bus/address cannot be used simultaneously"
@@ -194,10 +193,11 @@ def _recv_internal(self, timeout: float | None) -> tuple[can.Message | None, boo
194193
return msg, False
195194

196195
def shutdown(self):
197-
if self._is_shutdown:
196+
already_shutdown = self._is_shutdown
197+
super().shutdown()
198+
if already_shutdown:
198199
return
199200

200-
super().shutdown()
201201
self.gs_usb.stop()
202202
if self._index is not None:
203203
# Avoid errors on subsequent __init() by repeating the .scan() and .start() that would otherwise fail
@@ -211,4 +211,3 @@ def shutdown(self):
211211
gs_usb.stop()
212212
except usb.core.USBError:
213213
pass
214-
self._is_shutdown = True

0 commit comments

Comments
 (0)