code: def watch_process(self, process):
          
  
          status = process["psutil"].status()
  
          # TODO: how to avoid zombies?
          # print process["pid"], status
  
          if process.get("terminate"):
              if status in ("zombie", "dead"):
                  process["dead"] = True
              elif process.get("terminate_at"):
                  if time.time() > (process["terminate_at"] + 5):
                      log.warning("Process %s had to be sent SIGKILL" % (process["pid"], ))
                      process["subprocess"].send_signal(signal.SIGKILL)
                  elif time.time() > process["terminate_at"]:
                      log.warning("Process %s had to be sent SIGTERM" % (process["pid"], ))
                      process["subprocess"].send_signal(signal.SIGTERM)
  
          else:
              if status in ("zombie", "dead"):
                  # Restart a new process right away (TODO: sleep a bit? max retries?)
                  process["dead"] = True
                  self.spawn(process["command"])
  
              elif status not in ("running", "sleeping"):
                  log.warning("Process %s was in status %s" % (process["pid"], status))
docs: Manages the status of a single process