Changeset 1434 for pykota/trunk

Show
Ignore:
Timestamp:
04/13/04 11:38:03 (21 years ago)
Author:
jalet
Message:

More work on correct child processes handling

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/tool.py

    r1433 r1434  
    2222# 
    2323# $Log$ 
     24# Revision 1.82  2004/04/13 09:38:03  jalet 
     25# More work on correct child processes handling 
     26# 
    2427# Revision 1.81  2004/04/09 22:24:47  jalet 
    2528# Began work on correct handling of child processes when jobs are cancelled by 
     
    316319import gettext 
    317320import locale 
     321import signal 
    318322 
    319323from mx import DateTime 
     
    753757        # it to any child if needed. 
    754758        self.gotSigTerm = 0 
     759        self.childProcesses = {} 
    755760        signal.signal(signal.SIGPIPE, signal.SIG_IGN) 
    756761        signal.signal(signal.SIGTERM, self.sigterm_handler) 
    757762         
     763    def registerChild(self, pid, name) :     
     764        """Registers a child process so that we will be able to kill it later if needed.""" 
     765        self.childProcesses[pid] = name 
     766         
     767    def unregisterChild(self, pid) :     
     768        try : 
     769            del self.childProcesses[pid] 
     770        except KeyError :     
     771            pass 
     772             
    758773    def sigterm_handler(self, signum, frame) : 
    759774        """Sets a global variable whenever SIGTERM is received.""" 
     
    762777        self.gotSigTerm = 1 
    763778        self.logger.log_message(_("SIGTERM received, job %s cancelled.") % self.jobid, "info") 
     779        for (childpid, childname) in self.childProcesses.items() : 
     780            try : 
     781                os.kill(childpid, signal.SIGTERM) 
     782            except :     
     783                pass 
     784            else :     
     785                self.logdebug("SIGTERM sent to process %s (%s)." % (childpid, childname)) 
    764786         
    765787    def exportJobInfo(self) :