예제 #1
0
파일: system.py 프로젝트: vlaght/iktomi
 def test_terminate_child_true(self):
     pid = os.fork()
     if pid:
         started = time.time()
         success = terminate(pid, signal.SIGKILL, 0.5)
         finished = time.time()
         self.assertTrue(success)
         self.assertFalse(is_running(pid))
         self.assertLess(finished - started, 1)
     else:
         time.sleep(3)
         os._exit(os.EX_OK)
예제 #2
0
 def test_terminate_child_true(self):
     pid = os.fork()
     if pid:
         started = time.time()
         success = terminate(pid, signal.SIGKILL, 0.5)
         finished = time.time()
         self.assertTrue(success)
         self.assertFalse(is_running(pid))
         self.assertLess(finished-started, 1)
     else:
         time.sleep(3)
         os._exit(os.EX_OK)
예제 #3
0
파일: system.py 프로젝트: vlaght/iktomi
    def test_terminate_false(self):
        pid = os.fork()

        if pid:
            started = time.time()
            success = terminate(pid, 0, 0.5)
            finished = time.time()
            self.assertFalse(success)
            self.assertTrue(is_running(pid))
            self.assertLess(finished - started, 1)

            # Cleaning up
            os.kill(pid, signal.SIGKILL)
            os.waitpid(pid, 0)

        else:
            time.sleep(3)
            os._exit(os.EX_OK)
예제 #4
0
파일: system.py 프로젝트: vlaght/iktomi
 def test_terminate_alien_true(self):
     _, pidfile = tempfile.mkstemp()
     child_pid = os.fork()
     if child_pid:
         time.sleep(0.1)
         with open(pidfile) as fp:
             pid = int(fp.read())
         self.assertTrue(is_running(pid))
         started = time.time()
         success = terminate(pid, signal.SIGKILL, 0.5)
         finished = time.time()
         self.assertTrue(success)
         self.assertFalse(is_running(pid))
         self.assertLess(finished - started, 1)
     else:
         doublefork(pidfile, '/dev/null', '.', 0)
         time.sleep(3)
         os._exit(os.EX_OK)
예제 #5
0
    def test_terminate_false(self):
        pid = os.fork()

        if pid:
            started = time.time()
            success = terminate(pid, 0, 0.5)
            finished = time.time()
            self.assertFalse(success)
            self.assertTrue(is_running(pid))
            self.assertLess(finished-started, 1)

            # Cleaning up
            os.kill(pid, signal.SIGKILL)
            os.waitpid(pid, 0)

        else:
            time.sleep(3)
            os._exit(os.EX_OK)
예제 #6
0
 def test_terminate_alien_true(self):
     _, pidfile = tempfile.mkstemp()
     child_pid = os.fork()
     if child_pid:
         time.sleep(0.1)
         with open(pidfile) as fp:
             pid = int(fp.read())
         self.assertTrue(is_running(pid))
         started = time.time()
         success = terminate(pid, signal.SIGKILL, 0.5)
         finished = time.time()
         self.assertTrue(success)
         self.assertFalse(is_running(pid))
         self.assertLess(finished-started, 1)
     else:
         doublefork(pidfile, '/dev/null', '.', 0)
         time.sleep(3)
         os._exit(os.EX_OK)
예제 #7
0
파일: fcgi.py 프로젝트: Lehych/iktomi
    def command_stop(self):
        '''
        Stop a server::

            ./manage.py flup:stop
        '''
        if self.pidfile:
            if not os.path.exists(self.pidfile):
                sys.exit("Pidfile {!r} doesn't exist".format(self.pidfile))
            with open(self.pidfile) as pidfile:
                pid = int(pidfile.read())
            for sig in [signal.SIGINT, signal.SIGTERM, signal.SIGKILL]:
                try:
                    if terminate(pid, sig, 3):
                        os.remove(self.pidfile)
                        sys.exit()
                except OSError, exc:
                    if exc.errno != errno.ESRCH:
                        raise
                    elif sig == signal.SIGINT:
                        sys.exit('Not running')
예제 #8
0
파일: fcgi.py 프로젝트: motor23/cmstest
    def command_stop(self):
        '''
        Stop a server::

            ./manage.py flup:stop
        '''
        if self.pidfile:
            if not os.path.exists(self.pidfile):
                sys.exit("Pidfile {!r} doesn't exist".format(self.pidfile))
            with open(self.pidfile) as pidfile:
                pid = int(pidfile.read())
            for sig in [signal.SIGINT, signal.SIGTERM, signal.SIGKILL]:
                try:
                    if terminate(pid, sig, 3):
                        os.remove(self.pidfile)
                        sys.exit()
                except OSError as exc:
                    if exc.errno != errno.ESRCH:
                        raise
                    elif sig == signal.SIGINT:
                        sys.exit('Not running')
        sys.exit('No pidfile provided')
예제 #9
0
파일: fcgi.py 프로젝트: SmartTeleMax/iktomi
    def command_stop(self):
        """
        Stop a server::

            ./manage.py flup:stop
        """
        if self.pidfile:
            if not os.path.exists(self.pidfile):
                sys.exit("Pidfile {!r} doesn't exist".format(self.pidfile))
            with open(self.pidfile) as pidfile:
                pid = int(pidfile.read())
            for sig in [signal.SIGINT, signal.SIGTERM, signal.SIGKILL]:
                try:
                    if terminate(pid, sig, 3):
                        os.remove(self.pidfile)
                        # NOTE: we are not performing sys.exit here,
                        # otherwise restart command will not work
                        return
                except OSError as exc:
                    if exc.errno != errno.ESRCH:
                        raise
                    elif sig == signal.SIGINT:
                        sys.exit("Not running")
        sys.exit("No pidfile provided")