From 36bbb6690f6a5327c537f12d7ec4bb74b682d4fe Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Sun, 8 Nov 2020 22:34:57 +0100 Subject: [PATCH] handle socket error when closing --- src/escpos/printer.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/escpos/printer.py b/src/escpos/printer.py index 59bacad..47834f6 100644 --- a/src/escpos/printer.py +++ b/src/escpos/printer.py @@ -242,7 +242,10 @@ class Network(Escpos): def close(self): """ Close TCP connection """ if self.device is not None: - self.device.shutdown(socket.SHUT_RDWR) + try: + self.device.shutdown(socket.SHUT_RDWR) + except socket.error: + pass self.device.close()