]> git.llucax.com Git - software/pymin.git/commitdiff
Make procman.ProcessManager return True is an action could be taken (refs #11).
authorLeandro Lucarella <llucax@gmail.com>
Wed, 21 May 2008 16:40:59 +0000 (13:40 -0300)
committerLeandro Lucarella <llucax@gmail.com>
Wed, 21 May 2008 18:02:48 +0000 (15:02 -0300)
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.

pymin/procman.py

index 0d67b9b1209fff69b6bf318243a5523b9e73ff4d..0bfb721018c6a61d6d3a30e72bad6cf8c6f0d361 100644 (file)
@@ -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)