Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.14] gh-138004: Fix setting a thread name on OpenIndiana (GH-138017) #138384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
miss-islington wants to merge 1 commit into python:3.14
base: 3.14
Choose a base branch
Loading
from miss-islington:backport-c19db1d-3.14
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions Lib/test/test_threading.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2230,6 +2230,9 @@ def test__all__(self):
@unittest.skipUnless(hasattr(_thread, 'set_name'), "missing _thread.set_name")
@unittest.skipUnless(hasattr(_thread, '_get_name'), "missing _thread._get_name")
def test_set_name(self):
# Ensure main thread name is restored after test
self.addCleanup(_thread.set_name, _thread._get_name())

# set_name() limit in bytes
truncate = getattr(_thread, "_NAME_MAXLEN", None)
limit = truncate or 100
Expand Down Expand Up @@ -2269,7 +2272,8 @@ def test_set_name(self):
tests.append(os_helper.TESTFN_UNENCODABLE)

if sys.platform.startswith("sunos"):
encoding = "utf-8"
# Use ASCII encoding on Solaris/Illumos/OpenIndiana
encoding = "ascii"
else:
encoding = sys.getfilesystemencoding()

Expand All @@ -2285,7 +2289,7 @@ def work():
if truncate is not None:
encoded = encoded[:truncate]
if sys.platform.startswith("sunos"):
expected = encoded.decode("utf-8", "surrogateescape")
expected = encoded.decode("ascii", "surrogateescape")
else:
expected = os.fsdecode(encoded)
else:
Expand All @@ -2304,7 +2308,11 @@ def work():
if '0円' in expected:
expected = expected.split('0円', 1)[0]

with self.subTest(name=name, expected=expected):
with self.subTest(name=name, expected=expected, thread="main"):
_thread.set_name(name)
self.assertEqual(_thread._get_name(), expected)

with self.subTest(name=name, expected=expected, thread="worker"):
work_name = None
thread = threading.Thread(target=work, name=name)
thread.start()
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ Weilin Du
John DuBois
Paul Dubois
Jacques Ducasse
Jadon Duff
Andrei Dorian Duma
Graham Dumpleton
Quinn Dunkan
Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +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.
9 changes: 6 additions & 3 deletions Modules/_threadmodule.c
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2471,7 +2471,9 @@ _thread__get_name_impl(PyObject *module)
}

#ifdef __sun
return PyUnicode_DecodeUTF8(name, strlen(name), "surrogateescape");
// gh-138004: Decode Solaris/Illumos (e.g. OpenIndiana) thread names
// from ASCII, since OpenIndiana only supports ASCII names.
return PyUnicode_DecodeASCII(name, strlen(name), "surrogateescape");
#else
return PyUnicode_DecodeFSDefault(name);
#endif
Expand Down Expand Up @@ -2509,8 +2511,9 @@ _thread_set_name_impl(PyObject *module, PyObject *name_obj)
{
#ifndef MS_WINDOWS
#ifdef __sun
// Solaris always uses UTF-8
const char *encoding = "utf-8";
// gh-138004: Encode Solaris/Illumos thread names to ASCII,
// since OpenIndiana does not support non-ASCII names.
const char *encoding = "ascii";
#else
// Encode the thread name to the filesystem encoding using the "replace"
// error handler
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /