Changeset 1183
- Timestamp:
- 11/14/03 19:31:27 (21 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r1182 r1183 24 24 # 25 25 # $Log$ 26 # Revision 1.5 2003/11/14 18:31:27 jalet 27 # Not perfect, but seems to work with the poll() loop. 28 # 26 29 # Revision 1.4 2003/11/14 17:04:15 jalet 27 30 # More (untested) work on the CUPS backend. … … 65 68 66 69 def _run_child(self, cmd): 67 for i in range(3, MAXFD):70 for i in range(3, 256): # TODO : MAXFD in original popen2 module 68 71 try: 69 72 os.close(i) … … 229 232 else : 230 233 infile = sys.stdin 234 realbackend = os.path.join(os.path.split(sys.argv[0])[0], thebackend.originalbackend) 231 235 subprocess = PyKotaPopen3([realbackend] + sys.argv[1:], capturestderr=1, arg0=os.environ["DEVICE_URI"]) 232 236 pollster = select.poll() 233 pollster.register(subprocess.fromchild, select.POLLIN) 234 pollster.register(subprocess.childerr, select.POLLIN) 235 pollster.register(subprocess.tochild, select.POLLOUT) 237 pollster.register(infile.fileno(), select.POLLIN) 238 pollster.register(subprocess.fromchild.fileno(), select.POLLIN) 239 pollster.register(subprocess.childerr.fileno(), select.POLLIN) 240 pollster.register(subprocess.tochild.fileno(), select.POLLOUT) 241 inputdata = "" 236 242 end = 0 237 243 while not end : 238 244 availablestreams = pollster.poll() 239 245 for (stream, mask) in availablestreams : 246 if mask & select.POLLHUP : 247 if stream == infile.fileno() : 248 end = 1 240 249 if mask & select.POLLOUT : 241 data = infile.read(256 * 1024) 242 if data : 243 os.write(stream, data) 244 else : 245 end = 1 250 if stream == subprocess.tochild.fileno() : 251 if inputdata : 252 os.write(stream, inputdata) 253 inputdata = "" 246 254 if mask & select.POLLIN : 247 255 data = os.read(stream, 256 * 1024) 248 if stream == pollster.fromchild.fileno() : 256 if stream == infile.fileno() : 257 inputdata += data 258 elif stream == subprocess.fromchild.fileno() : 249 259 sys.stdout.write(data) 250 elif stream == pollster.childerr.fileno() :260 elif stream == subprocess.childerr.fileno() : 251 261 sys.stderr.write(data) 262 if inputdata : 263 try : 264 os.write(subprocess.tochild.fileno(), inputdata) 265 except : 266 pass 267 sys.stdout.flush() 268 sys.stderr.flush() 252 269 subprocess.fromchild.close() 253 270 subprocess.childerr.close() … … 261 278 thebackend.logger.log_message(_("CUPS backend %s died abnormally.") % realbackend, "error") 262 279 retcode = -1 263 264 #realbackend = os.path.join(os.path.split(sys.argv[0])[0], thebackend.originalbackend)265 #retcode = os.spawnve(os.P_WAIT, realbackend, [os.environ["DEVICE_URI"]] + sys.argv[1:], os.environ)266 280 267 281 # stops accounting.