def __init__(self, *args, **kwargs): self.__subproc = subprocess.Popen(*args, **kwargs) self._pid = self.__subproc.pid self._gone = False self._platform_impl = _psplatform.Process(self._pid) self._last_sys_cpu_times = None self._last_proc_cpu_times = None try: self.create_time except AccessDenied: pass except NoSuchProcess: raise NoSuchProcess(self._pid, None, "no process found with pid %s" % pid)
def __init__(self, pid): """Create a new Process object for the given pid. Raises NoSuchProcess if pid does not exist. Note that most of the methods of this class do not make sure the PID of the process being queried has been reused. That means you might end up retrieving an information referring to another process in case the original one this instance refers to is gone in the meantime. The only exceptions for which process identity is pre-emptively checked are: - parent - get_children() - set_nice() - suspend() - resume() - send_signal() - terminate() - kill() To prevent this problem for all other methods you can: - use is_running() before querying the process - if you're continuously iterating over a set of Process instances use process_iter() which pre-emptively checks process identity for every yielded instance """ if not _PY3: if not isinstance(pid, (int, long)): raise TypeError('pid must be an integer') if pid < 0: raise ValueError('pid must be a positive integer') self._pid = pid self._gone = False self._ppid = None # platform-specific modules define an _psplatform.Process # implementation class self._platform_impl = _psplatform.Process(pid) self._last_sys_cpu_times = None self._last_proc_cpu_times = None # cache creation time for later use in is_running() method try: self.create_time except AccessDenied: pass except NoSuchProcess: raise NoSuchProcess(pid, None, 'no process found with pid %s' % pid)
def __init__(self, pid): """Create a new Process object, raises NoSuchProcess if the PID does not exist, and ValueError if the parameter is not an integer PID. """ if not isinstance(pid, int): raise ValueError("an integer is required") if not pid_exists(pid): raise NoSuchProcess(pid, None, "no process found with pid %s" % pid) self._pid = pid # platform-specific modules define an _psplatform.Process # implementation class self._platform_impl = _psplatform.Process(pid) self._last_sys_cpu_times = None self._last_proc_cpu_times = None
def __init__(self, pid): """Create a new Process object for the given pid. Raises NoSuchProcess if pid does not exist. """ self._pid = pid self._gone = False # platform-specific modules define an _psplatform.Process # implementation class self._platform_impl = _psplatform.Process(pid) self._last_sys_cpu_times = None self._last_proc_cpu_times = None # cache creation time for later use in is_running() method try: self.create_time except AccessDenied: pass except NoSuchProcess: raise NoSuchProcess(pid, None, 'no process found with pid %s' % pid)
def __init__(self, *args, **kwargs): self.__subproc = subprocess.Popen(*args, **kwargs) self._pid = self.__subproc.pid self._platform_impl = _psplatform.Process(self._pid) self._last_sys_cpu_times = None self._last_proc_cpu_times = None