Changeset 1289
- Timestamp:
- 01/13/04 11:48:28 (21 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r1285 r1289 24 24 # 25 25 # $Log$ 26 # Revision 1.23 2004/01/13 10:48:28 jalet 27 # Small streams polling loop modification. 28 # 26 29 # Revision 1.22 2004/01/12 22:43:40 jalet 27 30 # New formula to compute a job's price … … 251 254 outdata = "" 252 255 errdata = "" 253 endinput = 0 256 endinput = endoutput = enderr = 0 257 inputclosed = outclosed = errclosed = 0 258 self.logdebug("Entering streams polling loop...") 254 259 status = -1 255 inputclosed = 0256 self.logdebug("Entering streams polling loop...")257 260 while status == -1 : 258 261 # First check if original backend is still alive … … 268 271 269 272 # In any case, deal with any remaining I/O 270 availablefds = pollster.poll() 273 availablefds = pollster.poll(5000) 274 if (not availablefds) and inputclosed and outputclosed and errclosed : 275 break 271 276 for (fd, mask) in availablefds : 272 277 # self.logdebug("file: %i mask: %04x" % (fd, mask)) … … 277 282 os.write(fd, indata) 278 283 indata = "" 284 if endinput : 285 pollster.unregister(tocfno) 286 os.close(tocfno) 287 self.logdebug("Closing real backend's stdin.") 288 inputclosed = 1 279 289 elif fd == stdoutfno : 280 290 if outdata : 281 291 os.write(fd, outdata) 282 292 outdata = "" 293 if endoutput : 294 pollster.unregister(stdoutfno) 295 outputclosed = 1 283 296 elif fd == stderrfno : 284 297 if errdata : 285 298 os.write(fd, errdata) 286 299 errdata = "" 300 if enderr : 301 pollster.unregister(stderrfno) 302 errclosed = 1 287 303 if (mask & select.POLLIN) or (mask & select.POLLPRI) : 288 304 # We have something to read … … 291 307 indata += data 292 308 if not data : # If yes, then no more input data 309 pollster.unregister(infno) 310 self.logdebug("Input data ends.") 293 311 endinput = 1 # this happens with real files. 294 312 elif fd == fromcfno : … … 302 320 # 303 321 # Some standard I/O stream has no more datas 322 pollster.unregister(fd) 304 323 if fd == infno : 305 324 # Here we are in the case where the input file is stdin. 306 325 # which has no more data to be read. 326 self.logdebug("Input data ends.") 307 327 endinput = 1 308 328 elif fd == fromcfno : 309 329 # This should never happen, since 310 330 # CUPS backends don't send anything on their 311 # standard output 312 if outdata : 313 os.write(stdoutfno, outdata) 314 outdata = "" 331 # standard output. 315 332 # We are no more interested in this file descriptor 316 pollster.unregister(fromcfno)317 333 os.close(fromcfno) 318 334 self.logdebug("Real backend's stdout ends.") 335 endoutput = 1 319 336 elif fd == cerrfno : 320 337 # Original CUPS backend has finished 321 # to write informations on its standard error 322 if errdata : 323 # Try to write remaining info (normally "Ready to print.") 324 os.write(stderrfno, errdata) 325 errdata = "" 326 # We are no more interested in this file descriptor 327 pollster.unregister(cerrfno) 338 # to write informations on its standard error. 339 # We are no more interested in this file descriptor . 328 340 os.close(cerrfno) 329 341 self.logdebug("Real backend's stderr ends.") 330 331 if endinput and not inputclosed : 332 # We deal with remaining input datas here 333 # because EOF can happen in two different 334 # situations and I don't want to duplicate 335 # code, nor making functions. 336 if indata : 337 os.write(tocfno, indata) 338 indata = "" 339 # Again, we're not interested in this file descriptor anymore. 340 pollster.unregister(tocfno) 341 os.close(tocfno) 342 inputclosed = 1 343 self.logdebug("Input data ends.") 342 enderr = 1 344 343 345 344 # Input file was a real file, we have to close it.