From 52efc0372c7e39a42ab1d3599e0cdde79172d8c0 Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Sun, 2 May 2021 23:07:38 +0200 Subject: [PATCH] ModemATCommandLink: fix AttributeError exception in __del__() self._sl will not be assigned if serial.Serial() fails. Change-Id: I179a7efd92eaa3469a17b6ef252b3949c44ea6ea --- pySim/transport/modem_atcmd.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pySim/transport/modem_atcmd.py b/pySim/transport/modem_atcmd.py index 43614f1a..2018ac23 100644 --- a/pySim/transport/modem_atcmd.py +++ b/pySim/transport/modem_atcmd.py @@ -43,7 +43,8 @@ class ModemATCommandLink(LinkBase): self.reset_card() def __del__(self): - self._sl.close() + if hasattr(self, '_sl'): + self._sl.close() def send_at_cmd(self, cmd, timeout=0.2, patience=0.002): # Convert from string to bytes, if needed