Skip to content

Commit 8fc613b

Browse files
committed
fix comments and move thread name reset in test
1 parent 99f13ec commit 8fc613b

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Lib/test/test_threading.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,9 +2281,6 @@ def test__all__(self):
22812281
@unittest.skipUnless(hasattr(_thread, 'set_name'), "missing _thread.set_name")
22822282
@unittest.skipUnless(hasattr(_thread, '_get_name'), "missing _thread._get_name")
22832283
def test_set_name(self):
2284-
# Ensure main thread name is restored after test
2285-
self.addCleanup(_thread.set_name, _thread._get_name())
2286-
22872284
# set_name() limit in bytes
22882285
truncate = getattr(_thread, "_NAME_MAXLEN", None)
22892286
limit = truncate or 100
@@ -2359,6 +2356,9 @@ def work():
23592356
if '\0' in expected:
23602357
expected = expected.split('\0', 1)[0]
23612358

2359+
# Ensure main thread name is restored after test
2360+
self.addCleanup(_thread.set_name, _thread._get_name())
2361+
23622362
with self.subTest(name=name, expected=expected, thread="main"):
23632363
_thread.set_name(name)
23642364
self.assertEqual(_thread._get_name(), expected)

Modules/_threadmodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,8 +2523,8 @@ _thread__get_name_impl(PyObject *module)
25232523
}
25242524

25252525
#ifdef __sun
2526-
// Decode Solaris/Illumos (e.g. OpenIndiana) thread names as ASCII
2527-
// since OpenIndiana only supports ASCII names.
2526+
// gh-138004: Decode Solaris/Illumos (e.g. OpenIndiana) thread names
2527+
// from ASCII, since OpenIndiana only supports ASCII names.
25282528
return PyUnicode_DecodeASCII(name, strlen(name), "surrogateescape");
25292529
#else
25302530
return PyUnicode_DecodeFSDefault(name);
@@ -2563,7 +2563,7 @@ _thread_set_name_impl(PyObject *module, PyObject *name_obj)
25632563
{
25642564
#ifndef MS_WINDOWS
25652565
#ifdef __sun
2566-
// Encode Solaris/Illumos thread names as ASCII
2566+
// gh-138004: Encode Solaris/Illumos thread names to ASCII,
25672567
// since OpenIndiana does not support non-ASCII names.
25682568
const char *encoding = "ascii";
25692569
#else

0 commit comments

Comments
 (0)