Changeset 1475 for pykota/trunk/pykota/requesters/external.py
- Timestamp:
- 05/13/04 15:59:30 (20 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/requesters/external.py
r1433 r1475 22 22 # 23 23 # $Log$ 24 # Revision 1.12 2004/05/13 13:59:30 jalet 25 # Code simplifications 26 # 24 27 # Revision 1.11 2004/04/09 22:24:47 jalet 25 28 # Began work on correct handling of child processes when jobs are cancelled by … … 63 66 # 64 67 68 import sys 65 69 import os 70 import popen2 71 import signal 66 72 from pykota.requester import PyKotaRequesterError 67 73 … … 82 88 if printer is None : 83 89 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) 85 93 try : 86 pagecounter = int( answer.readline().strip())94 pagecounter = int(child.fromchild.readline().strip()) 87 95 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 : 88 113 raise PyKotaRequesterError, _("Unable to query printer %s via EXTERNAL(%s)") % (printer, commandline) 89 answer.close()90 return pagecounter91 114