Skip to content

Commit

Permalink
refact
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Apr 17, 2024
1 parent 6767e80 commit 18758d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
11 changes: 5 additions & 6 deletions psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 18758d1

Please sign in to comment.