Show
Ignore:
Timestamp:
05/13/04 15:59:30 (20 years ago)
Author:
jalet
Message:

Code simplifications

Files:
1 modified

Legend:

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

    r1433 r1475  
    2222# 
    2323# $Log$ 
     24# Revision 1.12  2004/05/13 13:59:30  jalet 
     25# Code simplifications 
     26# 
    2427# Revision 1.11  2004/04/09 22:24:47  jalet 
    2528# Began work on correct handling of child processes when jobs are cancelled by 
     
    6366# 
    6467 
     68import sys 
    6569import os 
     70import popen2 
     71import signal 
    6672from pykota.requester import PyKotaRequesterError 
    6773 
     
    8288        if printer is None : 
    8389            raise PyKotaRequesterError, _("Unknown printer address in EXTERNAL(%s) for printer %s") % (commandline, self.printername) 
    84         answer = os.popen(commandline) 
     90        error = 1 
     91        pagecounter = None 
     92        child = popen2.Popen4(commandline)     
    8593        try : 
    86             pagecounter = int(answer.readline().strip()) 
     94            pagecounter = int(child.fromchild.readline().strip()) 
    8795        except ValueError :     
     96            pass 
     97        except IOError :     
     98            # we were interrupted by a signal, certainely a SIGTERM 
     99            # caused by the user cancelling the current job 
     100            try : 
     101                os.kill(child.pid, signal.SIGTERM) 
     102            except :     
     103                pass # already killed ? 
     104            self.kotabackend.logger.log_message(_("SIGTERM was sent to external requester %s (pid: %s)") % (commandline, child.pid), "info") 
     105        else :     
     106            error = 0 
     107        child.fromchild.close()     
     108        child.tochild.close() 
     109        status = child.wait() 
     110        if (not error) and os.WIFEXITED(status) and (not os.WEXITSTATUS(status)) : 
     111            return pagecounter 
     112        else :     
    88113            raise PyKotaRequesterError, _("Unable to query printer %s via EXTERNAL(%s)") % (printer, commandline)  
    89         answer.close() 
    90         return pagecounter 
    91114