Changeset 995

Show
Ignore:
Timestamp:
05/13/03 15:54:20 (22 years ago)
Author:
jalet
Message:

Better handling of broken pipes

Location:
pykota/trunk/pykota
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/accounters/external.py

    r991 r995  
    2121# 
    2222# $Log$ 
     23# Revision 1.2  2003/05/13 13:54:20  jalet 
     24# Better handling of broken pipes 
     25# 
    2326# Revision 1.1  2003/05/07 19:47:06  jalet 
    2427# v1.07 Release of the Shame is out ! 
     
    7881             
    7982        # launches external accounter 
    80         process = popen2.Popen3("%s" % self.arguments) 
     83        try : 
     84            process = popen2.Popen3("%s" % self.arguments) 
    8185         
    82         # feed it with our data 
    83         data = infile.read(256*1024)     
    84         while data : 
    85             process.tochild.write(data) 
    86             temporary.write(data) 
    87             data = infile.read(256*1024) 
    88         process.tochild.close() 
     86            # feed it with our data 
     87            data = infile.read(256*1024)     
     88            while data : 
     89                process.tochild.write(data) 
     90                temporary.write(data) 
     91                data = infile.read(256*1024) 
     92            process.tochild.close() 
    8993         
    90         # wait for child process to exit (or die) 
    91         retcode = process.wait() 
    92          
    93         # check exit status 
    94         if os.WIFEXITED(retcode) and not os.WEXITSTATUS(retcode) : 
    95             # tries to extract the job size from the external accounter's 
    96             # standard output 
    97             try : 
    98                 pagecount = int(process.fromchild.readline().strip()) 
    99             except (AttributeError, ValueError) : 
     94            # wait for child process to exit (or die) 
     95            retcode = process.wait() 
     96             
     97            # check exit status 
     98            if os.WIFEXITED(retcode) and not os.WEXITSTATUS(retcode) : 
     99                # tries to extract the job size from the external accounter's 
     100                # standard output 
     101                try : 
     102                    pagecount = int(process.fromchild.readline().strip()) 
     103                except (AttributeError, ValueError) : 
     104                    self.filter.logger.log_message(_("Unable to compute job size with external accounter %s") % self.arguments) 
     105                    pagecount = 0 
     106            else : 
    100107                self.filter.logger.log_message(_("Unable to compute job size with external accounter %s") % self.arguments) 
    101108                pagecount = 0 
    102         else : 
    103             self.filter.logger.log_message(_("Unable to compute job size with external accounter %s") % self.arguments) 
     109            process.fromchild.close()     
     110        except IOError, msg :     
     111            msg = "%s : %s" % (self.arguments, msg)  
     112            self.filter.logger.log_message(_("Unable to compute job size with external accounter %s") % msg) 
    104113            pagecount = 0 
    105         process.fromchild.close()     
    106114             
    107115        if temporary is not None :     
  • pykota/trunk/pykota/version.py

    r991 r995  
    2121# 
    2222 
    23 __version__ = "1.07_unofficial" 
     23__version__ = "1.08alpha1_unofficial" 
    2424 
    2525__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""