It seems that pthread_setname_np() only works with ASCII names here.
>>> import _thread >>> _thread.set_name('€') Traceback (most recent call last): File "<python-input-1>", line 1, in <module> _thread.set_name('€') ~~~~~~~~~~~~~~~~^^^^^ OSError: [Errno 22] Invalid argument
In addition to making the test more lenient, we can make _thread.set_name() more tolerant to such restriction -- use ASCII encoding with the "replace" or "ignore" error handler as a fallback.
cc @vstinner