Changeset 1433

Show
Ignore:
Timestamp:
04/10/04 00:24:47 (20 years ago)
Author:
jalet
Message:

Began work on correct handling of child processes when jobs are cancelled by
the user. Especially important when an external requester is running for a
long time.

Location:
pykota/trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r1411 r1433  
    2424# 
    2525# $Log$ 
     26# Revision 1.38  2004/04/09 22:24:46  jalet 
     27# Began work on correct handling of child processes when jobs are cancelled by 
     28# the user. Especially important when an external requester is running for a 
     29# long time. 
     30# 
    2631# Revision 1.37  2004/03/18 19:11:25  jalet 
    2732# Fix for raw jobs in cupspykota 
     
    190195class PyKotaBackend(PyKotaFilterOrBackend) :         
    191196    """A class for the pykota backend.""" 
    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          
    214197    def acceptJob(self) :         
    215198        """Returns the appropriate exit code to tell CUPS all is OK.""" 
  • pykota/trunk/pykota/accounters/querying.py

    r1271 r1433  
    2222# 
    2323# $Log$ 
     24# Revision 1.13  2004/04/09 22:24:47  jalet 
     25# Began work on correct handling of child processes when jobs are cancelled by 
     26# the user. Especially important when an external requester is running for a 
     27# long time. 
     28# 
    2429# Revision 1.12  2004/01/11 23:22:42  jalet 
    2530# Major code refactoring, it's way cleaner, and now allows automated addition 
     
    7277        """Initializes querying accounter.""" 
    7378        AccounterBase.__init__(self, kotabackend, arguments) 
    74         self.requester = openRequester(kotabackend.config, kotabackend.printername) 
     79        self.requester = openRequester(kotabackend, kotabackend.printername) 
    7580        self.isDelayed = 1 # With the pykota filter, accounting is delayed by one job 
    7681         
  • pykota/trunk/pykota/requester.py

    r1257 r1433  
    2222# 
    2323# $Log$ 
     24# Revision 1.13  2004/04/09 22:24:46  jalet 
     25# Began work on correct handling of child processes when jobs are cancelled by 
     26# the user. Especially important when an external requester is running for a 
     27# long time. 
     28# 
    2429# Revision 1.12  2004/01/08 14:10:32  jalet 
    2530# Copyright year changed. 
     
    7378    __str__ = __repr__ 
    7479     
    75 def openRequester(config, printername) : 
     80def openRequester(kotabackend, printername) : 
    7681    """Returns a connection handle to the appropriate requester.""" 
    77     (backend, args) = config.getRequesterBackend(printername) 
     82    (backend, args) = kotabackend.config.getRequesterBackend(printername) 
    7883    try : 
    7984        exec "from pykota.requesters import %s as requesterbackend" % backend.lower() 
     
    8186        raise PyKotaRequesterError, _("Unsupported requester backend %s") % backend 
    8287    else :     
    83         return requesterbackend.Requester(printername, args) 
     88        return requesterbackend.Requester(kotabackend, printername, args) 
  • pykota/trunk/pykota/requesters/external.py

    r1257 r1433  
    2222# 
    2323# $Log$ 
     24# Revision 1.11  2004/04/09 22:24:47  jalet 
     25# Began work on correct handling of child processes when jobs are cancelled by 
     26# the user. Especially important when an external requester is running for a 
     27# long time. 
     28# 
    2429# Revision 1.10  2004/01/08 14:10:33  jalet 
    2530# Copyright year changed. 
     
    6368class Requester : 
    6469    """A class to send queries to printers via external commands.""" 
    65     def __init__(self, printername, arguments) : 
     70    def __init__(self, kotabackend, printername, arguments) : 
    6671        """Sets instance vars depending on the current printer.""" 
     72        self.kotabackend = kotabackend 
    6773        self.printername = printername 
    6874        self.commandline = arguments.strip() 
  • pykota/trunk/pykota/requesters/snmp.py

    r1257 r1433  
    2222# 
    2323# $Log$ 
     24# Revision 1.14  2004/04/09 22:24:47  jalet 
     25# Began work on correct handling of child processes when jobs are cancelled by 
     26# the user. Especially important when an external requester is running for a 
     27# long time. 
     28# 
    2429# Revision 1.13  2004/01/08 14:10:33  jalet 
    2530# Copyright year changed. 
     
    7681class Requester : 
    7782    """A class to send queries to printers via SNMP.""" 
    78     def __init__(self, printername, arguments) : 
     83    def __init__(self, kotabackend, printername, arguments) : 
    7984        """Sets instance vars depending on the current printer.""" 
     85        self.kotabackend = kotabackend 
    8086        self.printername = printername 
    8187        args = [x.strip() for x in arguments.split(',')] 
  • pykota/trunk/pykota/tool.py

    r1426 r1433  
    2222# 
    2323# $Log$ 
     24# Revision 1.81  2004/04/09 22:24:47  jalet 
     25# Began work on correct handling of child processes when jobs are cancelled by 
     26# the user. Especially important when an external requester is running for a 
     27# long time. 
     28# 
    2429# Revision 1.80  2004/04/06 12:00:21  jalet 
    2530# uninitialized values caused problems 
     
    741746        self.exportJobInfo() 
    742747         
     748        # then deal with signals 
     749        # CUPS backends ignore SIGPIPE and exit(1) on SIGTERM 
     750        # Fortunately SIGPIPE is already ignored by Python 
     751        # It's there just in case this changes in the future. 
     752        # Here we have to handle SIGTERM correctly, and pass 
     753        # it to any child if needed. 
     754        self.gotSigTerm = 0 
     755        signal.signal(signal.SIGPIPE, signal.SIG_IGN) 
     756        signal.signal(signal.SIGTERM, self.sigterm_handler) 
     757         
     758    def sigterm_handler(self, signum, frame) : 
     759        """Sets a global variable whenever SIGTERM is received.""" 
     760        # SIGTERM will be ignore most of the time, but during 
     761        # the call to the real backend, we have to pass it through. 
     762        self.gotSigTerm = 1 
     763        self.logger.log_message(_("SIGTERM received, job %s cancelled.") % self.jobid, "info") 
     764         
    743765    def exportJobInfo(self) :     
    744766        """Exports job information to the environment."""