From 0707c16339c3918f77eeb83cb1d6047cdb2f0e10 Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Sat, 8 Oct 2022 11:14:46 +0200 Subject: [PATCH] fix: race condition in test_posix.TestProcess.test_cmdline (#2153) --- CREDITS | 2 +- HISTORY.rst | 2 ++ psutil/tests/test_posix.py | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CREDITS b/CREDITS index a44a16bdf..e53c1577d 100644 --- a/CREDITS +++ b/CREDITS @@ -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 diff --git a/HISTORY.rst b/HISTORY.rst index fa18f5167..f77b20607 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -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 ===== diff --git a/psutil/tests/test_posix.py b/psutil/tests/test_posix.py index ebbf7a6e8..d87322300 100755 --- a/psutil/tests/test_posix.py +++ b/psutil/tests/test_posix.py @@ -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())