Skip to content

Commit dc86a29

Browse files
committed
test_threading main name fixed, minor changes, news
1 parent cd26833 commit dc86a29

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

Lib/test/test_threading.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,6 +2281,9 @@ 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+
22842287
# set_name() limit in bytes
22852288
truncate = getattr(_thread, "_NAME_MAXLEN", None)
22862289
limit = truncate or 100
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
_thread.set_name() now retries with an ASCII fallback if pthread_setname_np() rejects UTF-8 names on some POSIX-compliant platforms.
1+
On Solaris/Illumos platforms, thread names are now encoded as ASCII to avoid errors on systems (e.g. OpenIndiana) that don't support non-ASCII names.

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 with "replace" to avoid decoding errors.
2527-
return PyUnicode_DecodeASCII(name, strlen(name), "replace");
2526+
// Decode Solaris/Illumos (e.g. OpenIndiana) thread names as ASCII since OpenIndiana only supports ASCII names.
2527+
return PyUnicode_DecodeASCII(name, strlen(name), "surrogateescape");
25282528
#else
25292529
return PyUnicode_DecodeFSDefault(name);
25302530
#endif
@@ -2562,7 +2562,7 @@ _thread_set_name_impl(PyObject *module, PyObject *name_obj)
25622562
{
25632563
#ifndef MS_WINDOWS
25642564
#ifdef __sun
2565-
// Decode Solaris/Illumos (e.g. OpenIndiana) thread names as ASCII to avoid decoding errors.
2565+
// Encode Solaris/Illumos thread names as ASCII since OpenIndiana does not support non-ASCII names
25662566
const char *encoding = "ascii";
25672567
#else
25682568
// Encode the thread name to the filesystem encoding using the "replace"

0 commit comments

Comments
 (0)