def stop(self, action="quit"): """ Quit the process. """ if not self._config.get("pidfile"): raise SimplevisorError("%s requires a pidfile" % action) pid = pid_read(self._config["pidfile"]) timeout = 10 if pid and timeout is not None: print("%s (pid %d) is being told to %s..." % (self.prog, pid, action)) pid_write(self._config["pidfile"], pid, action) while timeout >= 0: try: os.kill(pid, 0) except OSError: break timeout -= 1 time.sleep(0.5) try: os.kill(pid, 0) except OSError: print("%s (pid %d) does not seem to be running anymore" % (self.prog, pid)) sys.exit(0) pid_quit(self._config["pidfile"], self.prog) sys.exit(0)
def send_action(self, action="stop_children"): """ Tell the supervisor to execute an action. """ if not self._config.get("pidfile"): raise SimplevisorError("%s requires a pidfile" % action) pid = pid_read(self._config["pidfile"]) if pid: print("%s (pid %d) is being told to %s..." % (self.prog, pid, action)) pid_write(self._config["pidfile"], pid, action) elif pid is not None: print("%s does not seem to be running anymore" % (self.prog,))