def testProcessDiesAfterBeingTracked(self): p = Popen(["sleep", "1"]) zombiereaper.autoReapPID(p.pid) # wait for the grim reaper to arrive sleep(4) # Throws error because pid is not found or is not child self.assertRaises(OSError, os.waitpid, p.pid, os.WNOHANG)
def testProcessDiedBeforeBeingTracked(self): p = Popen(["sleep", "0"]) # wait for the process to die sleep(1) zombiereaper.autoReapPID(p.pid) # Throws error because pid is not found or is not child self.assertRaises(OSError, os.waitpid, p.pid, os.WNOHANG)
def terminating(proc): try: yield proc finally: try: if proc.poll() is None: logging.debug('Terminating process pid=%d' % proc.pid) proc.kill() if proc.poll() is None: zombiereaper.autoReapPID(proc.pid) except Exception: logging.exception('Failed to kill process %d' % proc.pid)
def _abort(self): self._aborted = True if self._proc.returncode is None: logging.debug('Job %r killing virt-v2v process', self._id) try: self._proc.kill() except OSError as e: if e.errno != errno.ESRCH: raise logging.debug('Job %r virt-v2v process not running', self._id) else: logging.debug('Job %r virt-v2v process was killed', self._id) finally: zombiereaper.autoReapPID(self._proc.pid)
def _rescan(): """ Called from supervdsm to perform rescan as root. """ timeout = config.getint('irs', 'scsi_rescan_maximal_timeout') proc = commands.execCmd([constants.EXT_FC_SCAN], sync=False, execCmdLogger=log) try: proc.wait(timeout) finally: if proc.returncode is None: zombiereaper.autoReapPID(proc.pid) raise Error("Timeout scanning (pid=%s)" % proc.pid) elif proc.returncode != 0: stderr = proc.stderr.read(512) raise Error("Scan failed: %r" % stderr)
def stop(self): try: os.kill(self.process.pid, signal.SIGKILL) except: pass self.process.poll() # Don't try to read if the process is in D state if (self.process.returncode is not None and self.process.returncode != 0): err = self.process.stderr.read() out = self.process.stdout.read() self.log.debug("Pool handler existed, OUT: '%s' ERR: '%s'", out, err) try: zombiereaper.autoReapPID(self.process.pid) except AttributeError: if zombiereaper is not None: raise
def __del__(self): if self._proc.returncode is None: zombiereaper.autoReapPID(self._proc.pid)