192 | | def __init__(self) : |
193 | | """Does normal initialization then installs signal handler.""" |
194 | | # Normal init |
195 | | PyKotaFilterOrBackend.__init__(self) |
196 | | |
197 | | # then deal with signals |
198 | | # CUPS backends ignore SIGPIPE and exit(1) on SIGTERM |
199 | | # Fortunately SIGPIPE is already ignored by Python |
200 | | # It's there just in case this changes in the future. |
201 | | # Here we have to handle SIGTERM correctly, and pass |
202 | | # it to the original backend if needed. |
203 | | self.gotSigTerm = 0 |
204 | | signal.signal(signal.SIGPIPE, signal.SIG_IGN) |
205 | | signal.signal(signal.SIGTERM, self.sigterm_handler) |
206 | | |
207 | | def sigterm_handler(self, signum, frame) : |
208 | | """Sets a global variable whenever SIGTERM is received.""" |
209 | | # SIGTERM will be ignore most of the time, but during |
210 | | # the call to the real backend, we have to pass it through. |
211 | | self.gotSigTerm = 1 |
212 | | self.logger.log_message(_("SIGTERM received, job %s cancelled.") % self.jobid, "info") |
213 | | |