Skip to content
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
d97417d
fix threadmodule ascii and make test more lenient
jadonduff Aug 21, 2025
1db08a7
📜🤖 Added by blurb_it.
blurb-it[bot] Aug 21, 2025
0606968
implement requested changes
jadonduff Aug 22, 2025
b556774
reformat and remove test news
jadonduff Aug 22, 2025
38a75d3
patch for windows & non-posix compliant platforms
jadonduff Aug 22, 2025
31731b1
patch
jadonduff Aug 22, 2025
83fe205
Check if generated files are up to date patch
jadonduff Aug 22, 2025
aadf7f3
test
jadonduff Aug 22, 2025
612a0a4
test2
jadonduff Aug 22, 2025
1fa51f8
test3
jadonduff Aug 22, 2025
d24d0bb
attempt fix
jadonduff Aug 22, 2025
95d289f
Merge branch 'main' into thread_name_fix
jadonduff Aug 22, 2025
d7a47bf
test
jadonduff Aug 22, 2025
1970a00
fix stray newline
jadonduff Aug 22, 2025
6395323
Merge branch 'main' into thread_name_fix
jadonduff Aug 22, 2025
241e097
Apply suggestions from code review
jadonduff Aug 22, 2025
66c058b
fixes
jadonduff Aug 22, 2025
f817412
apply fixes (built)
jadonduff Aug 22, 2025
3349464
remove dead code, fix err var, revert newline, fix comment
jadonduff Aug 23, 2025
ac3d3dd
redundant err var replaced
jadonduff Aug 23, 2025
1ab9ecd
replaced functions with inline code, moved into set_thread_name_with_…
jadonduff Aug 23, 2025
d9ba9e8
revert
jadonduff Aug 23, 2025
d7025f5
inline test
jadonduff Aug 23, 2025
3689044
test fix for "Check if generated files are up to date"
jadonduff Aug 23, 2025
246f880
fix linker error
jadonduff Aug 23, 2025
407b1e9
make regen
jadonduff Aug 23, 2025
dc43fc4
move functions and add inline for functions used once
jadonduff Aug 24, 2025
7aa256c
remove duplicated __sun enforcing utf-8 from encoder
jadonduff Aug 24, 2025
b4934a2
consolidate functions, remove unrelated changes
jadonduff Aug 24, 2025
ae5ac4b
clinic regen fix
jadonduff Aug 24, 2025
4fc368d
fix error/fallback (implement changes)
jadonduff Aug 24, 2025
392aa5a
fix whitespace lint issue in test_threading.py
jadonduff Aug 24, 2025
84daea4
Merge branch 'main' into thread_name_fix
jadonduff Aug 25, 2025
d5e9399
make _threadmodule.c clearer, remove unrelated change, add specific t…
jadonduff Aug 25, 2025
105d4e6
Merge branch 'main' into thread_name_fix
jadonduff Aug 26, 2025
c67e93d
Merge branch 'main' into thread_name_fix
jadonduff Aug 27, 2025
508f24d
add test for main and encode ascii
jadonduff Sep 2, 2025
25085bf
encode ascii on solaris/openindiana
jadonduff Sep 2, 2025
cd26833
Merge branch 'main' into thread_name_fix
jadonduff Sep 2, 2025
dc86a29
test_threading main name fixed, minor changes, news
jadonduff Sep 2, 2025
c9f554d
Merge branch 'main' into thread_name_fix
jadonduff Sep 2, 2025
c0f672e
Lint fix
jadonduff Sep 2, 2025
69796ff
Update replace to surrogateescape
jadonduff Sep 2, 2025
15c8481
fix comment length
jadonduff Sep 2, 2025
99f13ec
Merge branch 'main' into thread_name_fix
jadonduff Sep 2, 2025
8fc613b
fix comments and move thread name reset in test
jadonduff Sep 2, 2025
5e5effb
revert name reset to original position
jadonduff Sep 2, 2025
9690eee
Merge branch 'main' into thread_name_fix
jadonduff Sep 2, 2025
338593c
Update Modules/_threadmodule.c
serhiy-storchaka Sep 2, 2025
e642264
Fix EOL.
serhiy-storchaka Sep 2, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -2281,6 +2281,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 @@ -2320,7 +2323,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 @@ -2336,7 +2340,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 @@ -2355,7 +2359,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
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ Weilin Du
John DuBois
Paul Dubois
Jacques Ducasse
Jadon Duff
Andrei Dorian Duma
Graham Dumpleton
Quinn Dunkan
Expand Down
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.
11 changes: 7 additions & 4 deletions Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2523,7 +2523,9 @@ _thread__get_name_impl(PyObject *module)
}

#ifdef __sun
return PyUnicode_DecodeUTF8(name, strlen(name), "surrogateescape");
// Decode Solaris/Illumos (e.g. OpenIndiana) thread names as ASCII
// since OpenIndiana only supports ASCII names.
return PyUnicode_DecodeASCII(name, strlen(name), "surrogateescape");
#else
return PyUnicode_DecodeFSDefault(name);
#endif
Expand Down Expand Up @@ -2561,8 +2563,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";
// Encode Solaris/Illumos thread names as 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 Expand Up @@ -2873,4 +2876,4 @@ PyMODINIT_FUNC
PyInit__thread(void)
{
return PyModuleDef_Init(&thread_module);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change (newline?).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May have accidentally added a newline in a previous commit. It now matches the current _threadmodule.c in the main branch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this change.

Loading