From eacb7378bde6ec20b7d811b2a7a3dcf4a17d231a Mon Sep 17 00:00:00 2001 From: mayeut Date: Sat, 7 May 2022 20:44:16 +0200 Subject: [PATCH] fix: deadlock in psutil.tests.test_contracts.TestFetchAllProcesses.test_all Signed-off-by: mayeut --- psutil/tests/test_contracts.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/psutil/tests/test_contracts.py b/psutil/tests/test_contracts.py index 5c927d68da..513c2080ee 100755 --- a/psutil/tests/test_contracts.py +++ b/psutil/tests/test_contracts.py @@ -397,17 +397,28 @@ class TestFetchAllProcesses(PsutilTestCase): """ def setUp(self): - self.pool = multiprocessing.Pool() + if LINUX and GITHUB_ACTIONS: + # the pool sometimes deadlocks on linux + # don't use it in CI + self.pool = None + else: + self.pool = multiprocessing.Pool() def tearDown(self): - self.pool.terminate() - self.pool.join() + if self.pool is not None: + self.pool.terminate() + self.pool.join() def iter_proc_info(self): # Fixes "can't pickle : it's not the # same object as test_contracts.proc_info". from psutil.tests.test_contracts import proc_info - return self.pool.imap_unordered(proc_info, psutil.pids()) + if self.pool is None: + for pid in psutil.pids(): + yield proc_info(pid) + else: + for info in self.pool.imap_unordered(proc_info, psutil.pids()): + yield info def test_all(self): failures = []