Skip to content

Commit

Permalink
Improve __del__ error message (#1564)
Browse files Browse the repository at this point in the history
* avoid "Exception ignored in function BusABC.__del__"

* improve error message
  • Loading branch information
zariiii9003 authored Apr 12, 2023
1 parent ef69400 commit 1f2f29c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion can/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):

def __del__(self) -> None:
if not self._is_shutdown:
LOG.warning("%s was not properly shut down", self.__class__)
LOG.warning("%s was not properly shut down", self.__class__.__name__)
# We do some best-effort cleanup if the user
# forgot to properly close the bus instance
with contextlib.suppress(AttributeError):
Expand Down
9 changes: 6 additions & 3 deletions can/interfaces/vector/canlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# Import Standard Python Modules
# ==============================
import contextlib
import ctypes
import logging
import os
Expand Down Expand Up @@ -869,9 +870,11 @@ def flush_tx_buffer(self) -> None:

def shutdown(self) -> None:
super().shutdown()
self.xldriver.xlDeactivateChannel(self.port_handle, self.mask)
self.xldriver.xlClosePort(self.port_handle)
self.xldriver.xlCloseDriver()

with contextlib.suppress(VectorError):
self.xldriver.xlDeactivateChannel(self.port_handle, self.mask)
self.xldriver.xlClosePort(self.port_handle)
self.xldriver.xlCloseDriver()

def reset(self) -> None:
self.xldriver.xlDeactivateChannel(self.port_handle, self.mask)
Expand Down

0 comments on commit 1f2f29c

Please sign in to comment.