Skip to content

Commit

Permalink
fix: race condition in test_posix.TestProcess.test_cmdline
Browse files Browse the repository at this point in the history
On macOS the official python installer exposes a python wrapper that
executes a python executable hidden inside an application bundle inside
the Python framework.

There's a race condition in in test_posix.TestProcess.test_cmdline between
the ps call & the psutil call depending on the completion of the execve
call so let's retry on failure for this test.

Signed-off-by: mayeut <[email protected]>
  • Loading branch information
mayeut committed Oct 8, 2022
1 parent 7271ec7 commit c33a300
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ I: 1956

N: Matthieu Darbois
W: https://github.com/mayeut
I: 2039, 2142, 2147
I: 2039, 2142, 2147, 2153

N: Hugo van Kemenade
W: https://github.com/hugovk
Expand Down
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ XXXX-XX-XX
- 2147_, [macOS] Fix disk usage report on macOS 12+. (patch by Matthieu Darbois)
- 2150_, [Linux] `Process.threads()`_ may raise ``NoSuchProcess``. Fix race
condition. (patch by Daniel Li)
- 2153_, [macOS] Fix race condition in test_posix.TestProcess.test_cmdline.
(patch by Matthieu Darbois)

5.9.2
=====
Expand Down
6 changes: 6 additions & 0 deletions psutil/tests/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ def test_exe(self):
adjusted_ps_pathname = ps_pathname[:len(ps_pathname)]
self.assertEqual(ps_pathname, adjusted_ps_pathname)

# On macOS the official python installer exposes a python wrapper that
# executes a python executable hidden inside an application bundle inside
# the Python framework.
# There's a race condition between the ps call & the psutil call below
# depending on the completion of the execve call so let's retry on failure
@retry_on_failure()
def test_cmdline(self):
ps_cmdline = ps_args(self.pid)
psutil_cmdline = " ".join(psutil.Process(self.pid).cmdline())
Expand Down

0 comments on commit c33a300

Please sign in to comment.