Skip to content

Commit fda509c

Browse files
authored
Do not attempt to close an already-closed serial connection (#1853)
1 parent e3bc332 commit fda509c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pymodbus/transport/transport_serial.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ def close(self, exc=None):
5151
self.async_loop.remove_reader(self.sync_serial.fileno())
5252
self.sync_serial.close()
5353
self.sync_serial = None
54-
with contextlib.suppress(Exception):
55-
self._protocol.connection_lost(exc)
54+
if exc:
55+
with contextlib.suppress(Exception):
56+
self._protocol.connection_lost(exc)
5657

5758
def write(self, data) -> None:
5859
"""Write some data to the transport."""

0 commit comments

Comments
 (0)