From b7c6edc9e11a7add16492fdd9f7cbaa50db211da Mon Sep 17 00:00:00 2001 From: Dean Rispin Date: Mon, 29 Feb 2016 09:09:11 -0800 Subject: [PATCH] Add optional timeout variable for printer network connections --- escpos/printer.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/escpos/printer.py b/escpos/printer.py index bfdd492..be8aed8 100644 --- a/escpos/printer.py +++ b/escpos/printer.py @@ -152,20 +152,23 @@ class Network(Escpos): work the same with this class. For the address of the printer check its manuals. """ - def __init__(self, host, port=9100, *args, **kwargs): + def __init__(self, host, port=9100, timeout=60, *args, **kwargs): """ :param host : Printer's hostname or IP address :param port : Port to write to + :param timeout : timeout in seconds for the socket-library """ Escpos.__init__(self, *args, **kwargs) self.host = host self.port = port + self.timeout = timeout self.open() def open(self): """ Open TCP socket with ``socket``-library and set it as escpos device """ self.device = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.device.settimeout(self.timeout) self.device.connect((self.host, self.port)) if self.device is None: