Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve race condition in Process.threads() #2151

Merged
merged 2 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -798,3 +798,6 @@ N: Bernhard Urban-Forster
C: Austria
W: https://github.com/lewurm
I: 2135

N: Daniel Li
I: 2150
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ XXXX-XX-XX
undefined ``ethtool_cmd_speed`` symbol.
- 2142_, [POSIX]: `net_if_stats()`_ 's ``flags`` on Python 2 returned unicode
instead of str. (patch by Matthieu Darbois)
- 2150_, [Linux] `Process.threads()`_ may raise ``NoSuchProcess``. Fix race
condition. (patch by Daniel Li)

5.9.2
=====
Expand Down
8 changes: 4 additions & 4 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -2061,9 +2061,9 @@ def threads(self):
try:
with open_binary(fname) as f:
st = f.read().strip()
except FileNotFoundError:
# no such file or directory; it means thread
# disappeared on us
except (FileNotFoundError, ProcessLookupError):
# no such file or directory or no such process;
# it means thread disappeared on us
hit_enoent = True
continue
# ignore the first two values ("pid (exe)")
Expand Down Expand Up @@ -2217,7 +2217,7 @@ def open_files(self):
with open_binary(file) as f:
pos = int(f.readline().split()[1])
flags = int(f.readline().split()[1], 8)
except FileNotFoundError:
except (FileNotFoundError, ProcessLookupError):
# fd gone in the meantime; process may
# still be alive
hit_enoent = True
Expand Down