Skip to content

Commit 1f2f29c

Browse files
authored
Improve __del__ error message (#1564)
* avoid "Exception ignored in function BusABC.__del__" * improve error message
1 parent ef69400 commit 1f2f29c

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

can/bus.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
439439

440440
def __del__(self) -> None:
441441
if not self._is_shutdown:
442-
LOG.warning("%s was not properly shut down", self.__class__)
442+
LOG.warning("%s was not properly shut down", self.__class__.__name__)
443443
# We do some best-effort cleanup if the user
444444
# forgot to properly close the bus instance
445445
with contextlib.suppress(AttributeError):

can/interfaces/vector/canlib.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
# Import Standard Python Modules
88
# ==============================
9+
import contextlib
910
import ctypes
1011
import logging
1112
import os
@@ -869,9 +870,11 @@ def flush_tx_buffer(self) -> None:
869870

870871
def shutdown(self) -> None:
871872
super().shutdown()
872-
self.xldriver.xlDeactivateChannel(self.port_handle, self.mask)
873-
self.xldriver.xlClosePort(self.port_handle)
874-
self.xldriver.xlCloseDriver()
873+
874+
with contextlib.suppress(VectorError):
875+
self.xldriver.xlDeactivateChannel(self.port_handle, self.mask)
876+
self.xldriver.xlClosePort(self.port_handle)
877+
self.xldriver.xlCloseDriver()
875878

876879
def reset(self) -> None:
877880
self.xldriver.xlDeactivateChannel(self.port_handle, self.mask)

0 commit comments

Comments
 (0)