From 4357c9d5d3f5e9cfa22bd0e839e0c897a1059179 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Fri, 19 Aug 2022 18:21:19 +0200 Subject: [PATCH 1/2] gh-96125: Fix sys.thread_info.name on pthread platforms --- Lib/test/test_sys.py | 8 ++++++++ .../Library/2022-08-19-18-21-01.gh-issue-96125.ODcF1Y.rst | 2 ++ Python/thread.c | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2022-08-19-18-21-01.gh-issue-96125.ODcF1Y.rst diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 78da09d6abc0f9..202fb30a8a7e9d 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -628,6 +628,14 @@ def test_thread_info(self): self.assertEqual(len(info), 3) self.assertIn(info.name, ('nt', 'pthread', 'pthread-stubs', 'solaris', None)) self.assertIn(info.lock, ('semaphore', 'mutex+cond', None)) + if sys.platform.startswith(("linux", "freebsd")): + self.assertEqual(info.name, "pthread") + elif sys.platform == "win32": + self.assertEqual(info.name, "nt") + elif sys.platform == "emscripten": + self.assertIn(info.name, {"pthread", "pthread-stubs"}) + elif sys.platform == "wasi": + self.assertEqual(info.name, "pthread-stubs") @unittest.skipUnless(support.is_emscripten, "only available on Emscripten") def test_emscripten_info(self): diff --git a/Misc/NEWS.d/next/Library/2022-08-19-18-21-01.gh-issue-96125.ODcF1Y.rst b/Misc/NEWS.d/next/Library/2022-08-19-18-21-01.gh-issue-96125.ODcF1Y.rst new file mode 100644 index 00000000000000..326eb1f27b4279 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-08-19-18-21-01.gh-issue-96125.ODcF1Y.rst @@ -0,0 +1,2 @@ +Fix incorrect condition that cause ``sys.thread_info.name`` to be wrong on +pthread platforms. diff --git a/Python/thread.c b/Python/thread.c index e206a69c0507da..8c8a4e81895eb6 100644 --- a/Python/thread.c +++ b/Python/thread.c @@ -59,7 +59,7 @@ PyThread_init_thread(void) # define PYTHREAD_NAME "pthread-stubs" # include "thread_pthread_stubs.h" #elif defined(_POSIX_THREADS) -# if defined(__EMSCRIPTEN__) || !defined(__EMSCRIPTEN_PTHREADS__) +# if defined(__EMSCRIPTEN__) && !defined(__EMSCRIPTEN_PTHREADS__) # define PYTHREAD_NAME "pthread-stubs" # else # define PYTHREAD_NAME "pthread" From a79ba883923cb76ccfe0dd4b031b6b5f9c907b58 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Fri, 19 Aug 2022 21:13:51 +0200 Subject: [PATCH 2/2] Update Misc/NEWS.d/next/Library/2022-08-19-18-21-01.gh-issue-96125.ODcF1Y.rst Co-authored-by: Brett Cannon --- .../next/Library/2022-08-19-18-21-01.gh-issue-96125.ODcF1Y.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2022-08-19-18-21-01.gh-issue-96125.ODcF1Y.rst b/Misc/NEWS.d/next/Library/2022-08-19-18-21-01.gh-issue-96125.ODcF1Y.rst index 326eb1f27b4279..ba7d26a965821f 100644 --- a/Misc/NEWS.d/next/Library/2022-08-19-18-21-01.gh-issue-96125.ODcF1Y.rst +++ b/Misc/NEWS.d/next/Library/2022-08-19-18-21-01.gh-issue-96125.ODcF1Y.rst @@ -1,2 +1,2 @@ -Fix incorrect condition that cause ``sys.thread_info.name`` to be wrong on +Fix incorrect condition that causes ``sys.thread_info.name`` to be wrong on pthread platforms.