Changeset 3197 for pykota/trunk
- Timestamp:
- 06/28/07 21:58:07 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/accounters/pjl.py
r3195 r3197 78 78 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 79 79 try : 80 sock.settimeout(1.0) 80 81 sock.connect((self.printerHostname, self.port)) 81 82 except socket.error, msg : … … 83 84 return False 84 85 else : 85 sock.setblocking(False)86 86 self.sock = sock 87 87 self.closed = False … … 90 90 self.readthread = threading.Thread(target=self.readloop) 91 91 self.readthread.start() 92 time.sleep(1) 92 93 self.parent.filter.logdebug("Connected to printer %s:%s" % (self.printerHostname, self.port)) 93 94 return True … … 113 114 while not self.quitEvent.isSet() : 114 115 try : 115 answer = self.sock.recv(4096) 116 answer = self.sock.recv(1) 117 except socket.timeout : 118 pass 116 119 except socket.error, (err, msg) : 117 time.sleep(0.1) # We will try again later in all cases 118 if err != errno.EAGAIN : 119 self.parent.filter.printInfo(_("Problem while receiving PJL answer from %s:%s : %s") % (self.printerHostname, self.port, str(msg)), "warn") 120 self.parent.filter.printInfo(_("Problem while receiving PJL answer from %s:%s : %s") % (self.printerHostname, self.port, str(msg)), "warn") 120 121 else : 121 122 if answer : … … 131 132 """Retrieves a printer's internal page counter and status via PJL.""" 132 133 try : 133 self.sock.sendall(pjlMessage) 134 nbsent = self.sock.send(pjlMessage) 135 if nbsent != len(pjlMessage) : 136 raise socket.error, "Short write" 134 137 except socket.error, msg : 135 138 self.parent.filter.printInfo(_("Problem while sending PJL query to %s:%s : %s") % (self.printerHostname, self.port, str(msg)), "warn") … … 139 142 while (actualpagecount is None) or (self.printerStatus is None) : 140 143 try : 141 answer = self.queue.get(True, 5)144 answer = self.queue.get(True, 2) 142 145 except Queue.Empty : 143 146 self.parent.filter.logdebug("Timeout when reading printer's answer from %s:%s" % (self.printerHostname, self.port))