Show
Ignore:
Timestamp:
11/14/03 19:31:27 (20 years ago)
Author:
jalet
Message:

Not perfect, but seems to work with the poll() loop.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r1182 r1183  
    2424# 
    2525# $Log$ 
     26# Revision 1.5  2003/11/14 18:31:27  jalet 
     27# Not perfect, but seems to work with the poll() loop. 
     28# 
    2629# Revision 1.4  2003/11/14 17:04:15  jalet 
    2730# More (untested) work on the CUPS backend. 
     
    6568         
    6669    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 
    6871            try: 
    6972                os.close(i) 
     
    229232        else :     
    230233            infile = sys.stdin 
     234        realbackend = os.path.join(os.path.split(sys.argv[0])[0], thebackend.originalbackend) 
    231235        subprocess = PyKotaPopen3([realbackend] + sys.argv[1:], capturestderr=1, arg0=os.environ["DEVICE_URI"]) 
    232236        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 = "" 
    236242        end = 0 
    237243        while not end : 
    238244            availablestreams = pollster.poll() 
    239245            for (stream, mask) in availablestreams : 
     246                if mask & select.POLLHUP : 
     247                    if stream == infile.fileno() : 
     248                        end = 1 
    240249                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 = "" 
    246254                if mask & select.POLLIN :      
    247255                    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() : 
    249259                        sys.stdout.write(data) 
    250                     elif stream == pollster.childerr.fileno() :     
     260                    elif stream == subprocess.childerr.fileno() :     
    251261                        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() 
    252269        subprocess.fromchild.close() 
    253270        subprocess.childerr.close() 
     
    261278            thebackend.logger.log_message(_("CUPS backend %s died abnormally.") % realbackend, "error") 
    262279            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) 
    266280     
    267281    # stops accounting.