Пример #1
0
    def kill(self, group=True):
        """Kill the process. If group=True, all sub-processes will also be killed."""
        self.kill_called = True

        if mswindows:
            if group and self._job:
                winprocess.TerminateJobObject(self._job, 127)
            else:
                winprocess.TerminateProcess(self._handle, 127)
            self.returncode = 127
        else:
            if group:
                try:
                    os.killpg(self.pid, signal.SIGKILL)
                except:
                    pass
            else:
                os.kill(self.pid, signal.SIGKILL)

            # If we don't call os.wait() we end up with zombie processes
            # see bug 658509, but it seems to traceback on linux
            if sys.platform == "darwin":
                try:
                    os.wait()
                except OSError, e:
                    # The process doesn't exist anymore so we can ignore it
                    pass

            self.returncode = -9
Пример #2
0
 def terminate(self):
     """Terminates the process"""
     if self._job:
         winprocess.TerminateJobObject(self._job, 127)
         self.returncode = 127
     else:
         # Cannot call the parent class, as there is no terminate method
         # defined at the class level (it's added upon instantiation),
         # so this is a copy of subprocess.Popen.terminate() code.
         TerminateProcess(self._handle, 1)
Пример #3
0
 def terminate(self):
     """Terminates the process"""
     # Don't terminate a process that we know has already died.
     if self.returncode is not None:
         return
     if self._job:
         winprocess.TerminateJobObject(self._job, 127)
         self.returncode = 127
     else:
         Popen.terminate(self)
Пример #4
0
 def kill(self, group=True):
     """Kill the process. If group=True, all sub-processes will also be killed."""
     if mswindows:
         if group:
             winprocess.TerminateJobObject(self._job, 127)
         else:
             winprocess.TerminateProcess(self._handle, 127)
         self.returncode = 127
     else:
         if group:
             os.killpg(self.pid, signal.SIGKILL)
         else:
             os.kill(self.pid, signal.SIGKILL)
         self.returncode = -9
Пример #5
0
 def kill(self, group=True, s=None):
     """Kill the process. If group=True, all sub-processes will also be killed."""
     if mswindows:
         s = 127 if s is None else s
         if group:
             winprocess.TerminateJobObject(self._job, s)
         else:
             winprocess.TerminateProcess(self._handle, s)
         self.returncode = -s
     else:
         s = signal.SIGKILL if s is None else s
         if group:
             os.killpg(self.pid, s)
         else:
             os.kill(self.pid, s)
         self.returncode = -s
Пример #6
0
 def kill(self, group=True):
     """Kill the process. If group=True, all sub-processes will also be killed."""
     if mswindows:
         if group:
             winprocess.TerminateJobObject(self._job, 127)
         else:
             winprocess.TerminateProcess(self._handle, 127)
         self.returncode = 127    
     else:
         if sys.platform == 'cygwin':
             cmd = "taskkill /f /pid " + str(self.pid)
             if group:
                 cmd += " /t"
             os.system(cmd)
         elif group:    
             os.killpg(self.pid, signal.SIGKILL)
         else:
             os.kill(self.pid, signal.SIGKILL)
         self.returncode = -9
Пример #7
0
 def kill(self, group=True):
     """Kill the process. If group=True, all sub-processes will also be killed."""
     self.kill_called = True
     if mswindows:
         if group and self._job:
             winprocess.TerminateJobObject(self._job, 127)
         else:
             try:
                 winprocess.TerminateProcess(self._handle, 127)
             except:
                 # TODO: better error handling here
                 pass
         self.returncode = 127
     else:
         if group:
             try:
                 os.killpg(self.pid, signal.SIGKILL)
             except:
                 pass
         else:
             os.kill(self.pid, signal.SIGKILL)
         self.returncode = -9