Exemple #1
0
    def stopProcess(self, pid):
        """
        Stop the process with the given pid.
        Wait until the pid has disappeared.
        """
        startClock = time.clock()
        termClock = startClock + configure.processTermWait
        killClock = termClock + configure.processKillWait

        self.debug('stopping process with pid %d' % pid)
        if not termPid(pid):
            self.warning('No process with pid %d' % pid)
            return False

        # wait for the kill
        while (checkPidRunning(pid)):
            if time.clock() > termClock:
                self.warning("Process with pid %d has not responded to TERM " \
                    "for %d seconds, killing" % (pid,
                        configure.processTermWait))
                killPid(pid)
                # so it does not get triggered again
                termClock = killClock + 1.0

            if time.clock() > killClock:
                self.warning("Process with pid %d has not responded to KILL " \
                    "for %d seconds, stopping" % (pid,
                        configure.processKillWait))
                return False

            # busy loop until kill is done

        return True
Exemple #2
0
    def stopProcess(self, pid):
        """
        Stop the process with the given pid.
        Wait until the pid has disappeared.
        """
        startClock = time.clock()
        termClock = startClock + configure.processTermWait
        killClock = termClock + configure.processKillWait

        self.debug("stopping process with pid %d" % pid)
        if not termPid(pid):
            self.warning("No process with pid %d" % pid)
            return False

        # wait for the kill
        while checkPidRunning(pid):
            if time.clock() > termClock:
                self.warning(
                    "Process with pid %d has not responded to TERM "
                    "for %d seconds, killing" % (pid, configure.processTermWait)
                )
                killPid(pid)
                # so it does not get triggered again
                termClock = killClock + 1.0

            if time.clock() > killClock:
                self.warning(
                    "Process with pid %d has not responded to KILL "
                    "for %d seconds, stopping" % (pid, configure.processKillWait)
                )
                return False

            # busy loop until kill is done

        return True
 def testKillPid(self):
     ret = os.fork()
     if ret == 0:
         # child
         waitForTerm()
         os._exit(0)
     else:
         # parent
         self.failUnless(killPid(ret))
         os.waitpid(ret, 0)
         # now that it's gone, it should fail
         self.failIf(killPid(ret))
 def testKillPid(self):
     ret = os.fork()
     if ret == 0:
         # child
         waitForTerm()
         os._exit(0)
     else:
         # parent
         self.failUnless(killPid(ret))
         os.waitpid(ret, 0)
         # now that it's gone, it should fail
         self.failIf(killPid(ret))