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)
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)
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)
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)
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)
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)
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')
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')
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")