From a7f6e3ad798952240edf7e05dcef0f029fb7a2dc Mon Sep 17 00:00:00 2001 From: nnelson Date: Tue, 25 Jul 2023 11:03:46 -0500 Subject: [PATCH 01/10] add debug logging to shutdown & del --- can/bus.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/can/bus.py b/can/bus.py index 555389b0f..c09cc86c2 100644 --- a/can/bus.py +++ b/can/bus.py @@ -460,9 +460,12 @@ def shutdown(self) -> None: if self._is_shutdown: LOG.debug("%s is already shut down", self.__class__) return + else: + LOG.debug("%s shutdown needed", self.__class__) self._is_shutdown = True self.stop_all_periodic_tasks() + LOG.debug("Is shutdown = %s", self._is_shutdown) def __enter__(self) -> Self: return self @@ -476,6 +479,7 @@ def __exit__( self.shutdown() def __del__(self) -> None: + LOG.debug("Is shutdown = %s", self._is_shutdown) if not self._is_shutdown: LOG.warning("%s was not properly shut down", self.__class__.__name__) # We do some best-effort cleanup if the user From 88f330ff97305a0691df594c6d2dc95d10b7ae46 Mon Sep 17 00:00:00 2001 From: nnelson Date: Tue, 25 Jul 2023 14:18:01 -0500 Subject: [PATCH 02/10] increase new debug logging to warning --- can/bus.py | 6 +++--- can/interfaces/socketcan/socketcan.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/can/bus.py b/can/bus.py index c09cc86c2..8088fc918 100644 --- a/can/bus.py +++ b/can/bus.py @@ -461,11 +461,11 @@ def shutdown(self) -> None: LOG.debug("%s is already shut down", self.__class__) return else: - LOG.debug("%s shutdown needed", self.__class__) + LOG.warning("%s shutdown needed", self.__class__) self._is_shutdown = True self.stop_all_periodic_tasks() - LOG.debug("Is shutdown = %s", self._is_shutdown) + LOG.warning("Is shutdown = %s", self._is_shutdown) def __enter__(self) -> Self: return self @@ -479,7 +479,7 @@ def __exit__( self.shutdown() def __del__(self) -> None: - LOG.debug("Is shutdown = %s", self._is_shutdown) + LOG.warning("Is shutdown = %s", self._is_shutdown) if not self._is_shutdown: LOG.warning("%s was not properly shut down", self.__class__.__name__) # We do some best-effort cleanup if the user diff --git a/can/interfaces/socketcan/socketcan.py b/can/interfaces/socketcan/socketcan.py index 377fe6478..446396cf1 100644 --- a/can/interfaces/socketcan/socketcan.py +++ b/can/interfaces/socketcan/socketcan.py @@ -723,7 +723,7 @@ def shutdown(self) -> None: for channel, bcm_socket in self._bcm_sockets.items(): log.debug("Closing bcm socket for channel %s", channel) bcm_socket.close() - log.debug("Closing raw can socket") + log.warning("Closing raw can socket") self.socket.close() def _recv_internal( From 393514378008b987a1b33d2ef426746ef44de0d2 Mon Sep 17 00:00:00 2001 From: nnelson Date: Tue, 25 Jul 2023 15:17:34 -0500 Subject: [PATCH 03/10] create a unique version string --- can/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/__init__.py b/can/__init__.py index 46a461b38..7c6266f79 100644 --- a/can/__init__.py +++ b/can/__init__.py @@ -8,7 +8,7 @@ import logging from typing import Any, Dict -__version__ = "4.2.2" +__version__ = "4.2.2.99" __all__ = [ "ASCReader", "ASCWriter", From b90334ace7f7b667e4ee217df6017d4d59b1f407 Mon Sep 17 00:00:00 2001 From: nnelson Date: Tue, 25 Jul 2023 20:43:31 -0500 Subject: [PATCH 04/10] changed warnign to info --- can/bus.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/bus.py b/can/bus.py index 8088fc918..35a409231 100644 --- a/can/bus.py +++ b/can/bus.py @@ -481,7 +481,7 @@ def __exit__( def __del__(self) -> None: LOG.warning("Is shutdown = %s", self._is_shutdown) if not self._is_shutdown: - LOG.warning("%s was not properly shut down", self.__class__.__name__) + LOG.info("%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): From 15ab62315da8377fd3a9e3cae24adf536771ae6c Mon Sep 17 00:00:00 2001 From: nnelson Date: Wed, 26 Jul 2023 10:02:43 -0500 Subject: [PATCH 05/10] add socket.shutdown(2) --- can/interfaces/socketcan/socketcan.py | 1 + 1 file changed, 1 insertion(+) diff --git a/can/interfaces/socketcan/socketcan.py b/can/interfaces/socketcan/socketcan.py index 446396cf1..f461c4510 100644 --- a/can/interfaces/socketcan/socketcan.py +++ b/can/interfaces/socketcan/socketcan.py @@ -724,6 +724,7 @@ def shutdown(self) -> None: log.debug("Closing bcm socket for channel %s", channel) bcm_socket.close() log.warning("Closing raw can socket") + self.socket.shutdown(2) self.socket.close() def _recv_internal( From b1eb4904b29ff8cbcb6c3601c405f50386dcb23e Mon Sep 17 00:00:00 2001 From: nnelson Date: Wed, 26 Jul 2023 10:34:46 -0500 Subject: [PATCH 06/10] try local control of is_shutdown --- can/interfaces/socketcan/socketcan.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/can/interfaces/socketcan/socketcan.py b/can/interfaces/socketcan/socketcan.py index f461c4510..2e09e6dc6 100644 --- a/can/interfaces/socketcan/socketcan.py +++ b/can/interfaces/socketcan/socketcan.py @@ -724,8 +724,11 @@ def shutdown(self) -> None: log.debug("Closing bcm socket for channel %s", channel) bcm_socket.close() log.warning("Closing raw can socket") - self.socket.shutdown(2) self.socket.close() + try: + self._is_shutdown = True + except: + log.warning("self._is_shutdown = True -> FAILED") def _recv_internal( self, timeout: Optional[float] From 4f056ee53ef7ce31b993eeb71961aa0201ca68a7 Mon Sep 17 00:00:00 2001 From: nnelson Date: Wed, 26 Jul 2023 11:16:37 -0500 Subject: [PATCH 07/10] add a PASS logging of _is_shutdown --- can/interfaces/socketcan/socketcan.py | 1 + 1 file changed, 1 insertion(+) diff --git a/can/interfaces/socketcan/socketcan.py b/can/interfaces/socketcan/socketcan.py index 2e09e6dc6..f5d20cc9a 100644 --- a/can/interfaces/socketcan/socketcan.py +++ b/can/interfaces/socketcan/socketcan.py @@ -727,6 +727,7 @@ def shutdown(self) -> None: self.socket.close() try: self._is_shutdown = True + log.warning("self._is_shutdown = True -> PASS") except: log.warning("self._is_shutdown = True -> FAILED") From 925dde657a3d72b2b12fb21ae972408ed2c03bf9 Mon Sep 17 00:00:00 2001 From: nnelson Date: Thu, 27 Jul 2023 08:44:37 -0500 Subject: [PATCH 08/10] set logging leve in bus.py --- can/bus.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/can/bus.py b/can/bus.py index 35a409231..b077308f1 100644 --- a/can/bus.py +++ b/can/bus.py @@ -95,6 +95,8 @@ def __init__( :raises ~can.exceptions.CanInitializationError: If the bus cannot be initialized """ + LOG.setLevel(logging.DEBUG) + self._periodic_tasks: List[_SelfRemovingCyclicTask] = [] self.set_filters(can_filters) From 25bf2129048a19c0512168e55bbadb4bce98fe04 Mon Sep 17 00:00:00 2001 From: nnelson Date: Fri, 28 Jul 2023 12:53:08 -0500 Subject: [PATCH 09/10] removed shutdown code added --- can/interfaces/socketcan/socketcan.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/can/interfaces/socketcan/socketcan.py b/can/interfaces/socketcan/socketcan.py index f5d20cc9a..446396cf1 100644 --- a/can/interfaces/socketcan/socketcan.py +++ b/can/interfaces/socketcan/socketcan.py @@ -725,11 +725,6 @@ def shutdown(self) -> None: bcm_socket.close() log.warning("Closing raw can socket") self.socket.close() - try: - self._is_shutdown = True - log.warning("self._is_shutdown = True -> PASS") - except: - log.warning("self._is_shutdown = True -> FAILED") def _recv_internal( self, timeout: Optional[float] From 2dddbaf56a85bea55f25c46a60a16c7ec3e2b394 Mon Sep 17 00:00:00 2001 From: nnelson Date: Tue, 1 Aug 2023 08:57:29 -0500 Subject: [PATCH 10/10] attempt to remove the failing line --- can/interfaces/socketcan/socketcan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/interfaces/socketcan/socketcan.py b/can/interfaces/socketcan/socketcan.py index 446396cf1..aff04b43c 100644 --- a/can/interfaces/socketcan/socketcan.py +++ b/can/interfaces/socketcan/socketcan.py @@ -916,7 +916,7 @@ def receiver(event: threading.Event) -> None: bind_socket(receiver_socket, "vcan0") print("Receiver is waiting for a message...") event.set() - print(f"Receiver got: {capture_message(receiver_socket)}") + # print(f"Receiver got: {capture_message(receiver_socket)}") def sender(event: threading.Event) -> None: event.wait()