From 73a80da44dc53b5d048dde6e01fd9094cae3a155 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 568c1b033f..156f7f67d5 100755 --- a/psutil/tests/test_contracts.py +++ b/psutil/tests/test_contracts.py @@ -399,17 +399,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 = []