Exemplo n.º 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
Exemplo n.º 2
0
    def testTermPid(self):
        ret = os.fork()
        if ret == 0:
            # child
            time.sleep(4)
            os._exit(0)
        else:
            # parent
            self.failUnless(checkPidRunning(ret))
            self.failUnless(termPid(ret))

            os.waitpid(ret, 0)

            # now that it's gone, it should fail
            self.failIf(checkPidRunning(ret))
            self.failIf(termPid(ret))
Exemplo n.º 3
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
Exemplo n.º 4
0
    def testTermPid(self):
        ret = os.fork()
        if ret == 0:
            # child
            time.sleep(4)
            os._exit(0)
        else:
            # parent
            self.failUnless(checkPidRunning(ret))
            self.failUnless(termPid(ret))

            os.waitpid(ret, 0)

            # now that it's gone, it should fail
            self.failIf(checkPidRunning(ret))
            self.failIf(termPid(ret))