From: Leandro Lucarella Date: Wed, 21 May 2008 16:40:59 +0000 (-0300) Subject: Make procman.ProcessManager return True is an action could be taken (refs #11). X-Git-Url: https://git.llucax.com/software/pymin.git/commitdiff_plain/fbe65e123a74a532d8e603831cf35d58b9a9e03e?ds=sidebyside Make procman.ProcessManager return True is an action could be taken (refs #11). For start(), stop(), restart() and kill(), return True if the action could be taken. That is True if the process wasn't already running for start(), and for stop(), restart() and kill(), True if the process was already running. --- diff --git a/pymin/procman.py b/pymin/procman.py index 0d67b9b..0bfb721 100644 --- a/pymin/procman.py +++ b/pymin/procman.py @@ -110,13 +110,17 @@ class ProcessManager: def start(self, name): log.debug(u'ProcessManager.start(%s)', name) - assert name not in self.namemap - self._call(self.services[name]) + if name not in self.namemap: + self._call(self.services[name]) + return True + return False def stop(self, name): log.debug(u'ProcessManager.stop(%s)', name) - assert name in self.namemap - self.namemap[name].stop() + if name in self.namemap: + self.namemap[name].stop() + return True + return False def restart(self, name): log.debug(u'ProcessManager.restart(%s)', name) @@ -131,13 +135,17 @@ class ProcessManager: pi.restart() # add the new PID self.pidmap[pi.process.pid] = pi + return True else: self.start(name) + return False def kill(self, name, signum): log.debug(u'ProcessManager.kill(%s, %s)', name, signum) - assert name in self.namemap - self.namemap[name].kill(name, stop) + if name in self.namemap: + self.namemap[name].kill(name, stop) + return True + return False def sigchild_handler(self, signum, stack_frame=None): log.debug(u'ProcessManager.sigchild_handler(%s)', signum)