def __init__(self, command, linesep="\n", debug_level=logging.DEBUG, process_manager=False): self.logging_level = debug_level self.command = command self.fd = None self.pid = None self.linesep = linesep self.status = None self.kill_handler = [] ShellProcess._collect_session(self) self.killing = False self._execute() if process_manager: ProcessManager.register_pid(self.pid , self._die_event)
def kill(self): """ Kill subprocess """ try: ProcessManager.remove_pid(self.pid) if self.get_status() is None: os.kill(self.pid, signal.SIGKILL) logging.debug("Killing PID %d" % self.pid) else: logging.debug("Process PID %d return %d" % (self.pid, self.get_status())) except OSError: logging.log(self.logging_level, "Process %d is already killed." % (self.pid))