diff options
author | Victor Stinner <vstinner@python.org> | 2024-12-10 16:33:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-10 16:33:11 (GMT) |
commit | c91ccbe4ac0ec15c503521f539b3528db85871b4 (patch) | |
tree | f96337c4bcde0b6832fc4d49c713261d680e1d9b /Lib/test | |
parent | 9af96f440618304e7cc609c246e1f8c8b2d7a119 (diff) | |
download | cpython-c91ccbe4ac0ec15c503521f539b3528db85871b4.zip cpython-c91ccbe4ac0ec15c503521f539b3528db85871b4.tar.gz cpython-c91ccbe4ac0ec15c503521f539b3528db85871b4.tar.bz2 |
gh-59705: Set OS thread name when Thread.name is changed (#127702)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_threading.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index d05161f..3e164a1 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -2164,6 +2164,25 @@ class MiscTestCase(unittest.TestCase): self.assertEqual(work_name, expected, f"{len(work_name)=} and {len(expected)=}") + @unittest.skipUnless(hasattr(_thread, 'set_name'), "missing _thread.set_name") + @unittest.skipUnless(hasattr(_thread, '_get_name'), "missing _thread._get_name") + def test_change_name(self): + # Change the name of a thread while the thread is running + + name1 = None + name2 = None + def work(): + nonlocal name1, name2 + name1 = _thread._get_name() + threading.current_thread().name = "new name" + name2 = _thread._get_name() + + thread = threading.Thread(target=work, name="name") + thread.start() + thread.join() + self.assertEqual(name1, "name") + self.assertEqual(name2, "new name") + class InterruptMainTests(unittest.TestCase): def check_interrupt_main_with_signal_handler(self, signum): |