]> git.llucax.com Git - software/pymin.git/blobdiff - pymin/procman.py
Add ProcessManager.restart() method to block until the restart is done.
[software/pymin.git] / pymin / procman.py
index b89b7e63d6eeac0e5583904e85c30a0acf1c6f71..5cea4d4e1760989126cb77d94483cc493b551e45 100644 (file)
@@ -26,7 +26,6 @@ class ProcessInfo:
         self.signal = None
         self.process = None
         self.error_count = 0
         self.signal = None
         self.process = None
         self.error_count = 0
-        self.last_return = None
         self.running = False
     def start(self):
         assert self.process is None
         self.running = False
     def start(self):
         assert self.process is None
@@ -46,7 +45,7 @@ class ProcessInfo:
             self.kill(signal.SIGTERM)
     def kill(self, signum):
         assert self.process is not None
             self.kill(signal.SIGTERM)
     def kill(self, signum):
         assert self.process is not None
-        os.kill(pi.process.pid, signum)
+        os.kill(self.process.pid, signum)
         self.signal = signum
     def __repr__(self):
         pid = None
         self.signal = signum
     def __repr__(self):
         pid = None
@@ -85,7 +84,16 @@ class ProcessManager:
 
     def stop(self, name):
         assert name in self.namemap
 
     def stop(self, name):
         assert name in self.namemap
-        self.namemap[name].stop(name)
+        self.namemap[name].stop()
+
+    def restart(self, name):
+        logging.debug(u'ProcessManager.restart(%s)', name)
+        if name in self.namemap:
+            self.namemap[name].stop()
+            self.namemap[name].wait()
+            self.namemap[name].restart()
+        else:
+            self.namemap[name].start()
 
     def kill(self, name, signum):
         assert name in self.namemap
 
     def kill(self, name, signum):
         assert name in self.namemap
@@ -95,12 +103,13 @@ class ProcessManager:
         try:
             (pid, status) = os.waitpid(-1, os.WNOHANG)
         except OSError, e:
         try:
             (pid, status) = os.waitpid(-1, os.WNOHANG)
         except OSError, e:
-            if e.errno is e.ECHILD:
+            if e.errno is errno.ECHILD:
                 return
             raise
         while pid:
             if pid in self.pidmap:
                 p = self.pidmap[pid]
                 return
             raise
         while pid:
             if pid in self.pidmap:
                 p = self.pidmap[pid]
+                p.process.returncode = status
                 if p.callback is not None:
                     p.callback(self, p)
                 if p.dont_run or not p.persist or p.error_count >= p.max_errors:
                 if p.callback is not None:
                     p.callback(self, p)
                 if p.dont_run or not p.persist or p.error_count >= p.max_errors:
@@ -131,7 +140,7 @@ class ProcessManager:
         else: # is a pid
             if name in self.pidmap:
                 return self.pidmap[name]
         else: # is a pid
             if name in self.pidmap:
                 return self.pidmap[name]
-        return KeyError, name
+        raise KeyError, name
 
     def has(self, name):
         if isinstance(name, basestring): # is a name
 
     def has(self, name):
         if isinstance(name, basestring): # is a name