from cherrypy.process.plugins import Autoreloader
from cherrypy.process.plugins import SimplePlugin
+ Start our process and store our Popen object and pid.
+ if self.cmd and not self.pid:
+ # We can use a list or a string for the command.
if isinstance(self.cmd, basestring):
self.cmd = shlex.split(self.cmd)
self.proc = subprocess.Popen(self.cmd,
+ # Store the pid separately. When cherrypy restarts it does
+ # an exec which kills our Popen instance. We can use the
+ # pid to stop the process safely.
+ self.pid = self.proc.pid
+ Stop the process via the Popen object or pid.
+ if self.proc and self.proc.poll():
+ # We trust the process will end happily with a
+ # SIGTERM. Might need a hook to help things along if it
+ # We have been restarted which means our proc object is
+ # gone. We can still use our pid and os.kill directly.
+ os.kill(self.pid, signal.SIGTERM)
- if self.proc and self.proc.poll():
if __name__ == '__main__':