diff --git a/HISTORY.rst b/HISTORY.rst index 5221a123d..981355127 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -8,7 +8,7 @@ - 2366_, [Windows]: log debug message when using slower process APIs. - 2375_, [macOS]: provide arm64 wheels. (patch by Matthieu Darbois) - 2396_: `process_iter()`_ no longer pre-emptively checks whether PIDs have - been reused. As such it's around 20x times faster. + been reused. This makes `process_iter()`_ around 20x times faster. - 2396_: a new ``psutil.process_iter.cache_clear()`` API can be used the clear `process_iter()`_ internal cache. diff --git a/psutil/__init__.py b/psutil/__init__.py index 2d88a0289..934013819 100644 --- a/psutil/__init__.py +++ b/psutil/__init__.py @@ -608,16 +608,15 @@ def is_running(self): return False try: # Checking if PID is alive is not enough as the PID might - # have been reused by another process: we also want to - # verify process identity. - # Process identity / uniqueness over time is guaranteed by - # (PID + creation time) and that is verified in __eq__. + # have been reused by another process. Process identity / + # uniqueness over time is guaranteed by (PID + creation + # time) and that is verified in __eq__. self._pid_reused = self != Process(self.pid) if self._pid_reused: - self._gone = True # remove this PID from `process_iter()` internal cache _pmap.pop(self.pid, None) - return not self._pid_reused + raise NoSuchProcess(self.pid) + return True except ZombieProcess: # We should never get here as it's already handled in # Process.__init__; here just for extra safety.