mirror of
https://github.com/python/cpython.git
synced 2025-08-28 04:35:02 +00:00
gh-59705: Set OS thread name when Thread.name is changed (#127702)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
This commit is contained in:
parent
9af96f4406
commit
c91ccbe4ac
4 changed files with 43 additions and 7 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue