From b444ebcd72a7da8b8081172d52f2e7b36f0915c0 Mon Sep 17 00:00:00 2001 From: Guillaume Seguin Date: Sat, 25 Feb 2012 22:35:48 +0100 Subject: [PATCH] Handle the exceptions raised when printer is disconnected. --- printcore.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/printcore.py b/printcore.py index cadbc0e..fe8f8bf 100755 --- a/printcore.py +++ b/printcore.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with Printrun. If not, see . -from serial import Serial +from serial import Serial, SerialException from threading import Thread from select import error as SelectError import time, getopt, sys @@ -100,6 +100,9 @@ class printcore(): break else: raise + except SerialException, e: + print "Can't read from printer (disconnected?)." + break if(len(line)>1): self.log+=[line] @@ -279,7 +282,10 @@ class printcore(): self.sendcb(command) except: pass - self.printer.write(str(command+"\n")) + try: + self.printer.write(str(command+"\n")) + except SerialException, e: + print "Can't write to printer (disconnected?)." if __name__ == '__main__': baud = 115200