From d61646ffff43ed7517436631b360dd8bb92c328b Mon Sep 17 00:00:00 2001 From: Paolo Teti Date: Tue, 2 Jun 2020 12:08:17 +0200 Subject: [PATCH] Network disc: avoid to raise an error if 'bus' or 'notifier' is None If 'bus' is not connected yet and for other reasons an exception is raised and some 'finally' block contains a call to disconnect() an error is raised. --- canopen/network.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/canopen/network.py b/canopen/network.py index 01bbc290..70f5c361 100644 --- a/canopen/network.py +++ b/canopen/network.py @@ -119,8 +119,10 @@ def disconnect(self): for node in self.nodes.values(): if hasattr(node, "pdo"): node.pdo.stop() - self.notifier.stop() - self.bus.shutdown() + if self.notifier is not None: + self.notifier.stop() + if self.bus is not None: + self.bus.shutdown() self.bus = None self.check()