- def call(self, name, callback, persist, *args, **kw):
- proc = subprocess.Popen(*args, **kw)
- procinfo = ProcessInfo(name, proc, args, kw, callback, persist)
- self.namemap[name] = self.pidmap[proc.pid] = procinfo
+ def _call(self, pi):
+ pi.start()
+ self.namemap[pi.name] = self.pidmap[pi.process.pid] = pi
+
+ def once(self, name, command, callback=None, persist=False,
+ max_errors=3, *args, **kwargs):
+ log.debug(u'ProcessManager.once(%s, %s, %s, %s, %s, %s, %s)',
+ name, command, callback, persist, max_errors, args, kwargs)
+ assert not self.has(name)
+ pi = ProcessInfo(name, command, callback, persist, max_errors,
+ args, kwargs)
+ self._call(pi)
+ return pi
+
+ def start(self, name):
+ log.debug(u'ProcessManager.start(%s)', name)
+ assert name not in self.namemap
+ self._call(self.services[name])
+
+ def stop(self, name):
+ log.debug(u'ProcessManager.stop(%s)', name)
+ assert name in self.namemap
+ self.namemap[name].stop()
+
+ def restart(self, name):
+ log.debug(u'ProcessManager.restart(%s)', name)
+ # we have to check first in namemap in case is an unregistered
+ # process (added with once())
+ if name in self.namemap:
+ pi = self.namemap[name]
+ pi.stop()
+ pi.process.wait()
+ pi.restart()
+ else:
+ self.services[name].start()