Skip to content

test_set_name fails on OpenIndiana #138004

Closed

Description

@serhiy-storchaka

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

Linked PRs

Activity

  1. jadonduff commented on Aug 21, 2025

    @jadonduff
    Contributor

    Decided to try my first issue with Python - I attempted to create a fallback in the _threadmodule and made the test more lenient. See pull request for details.

    Please let me know if this was not the issue you were describing and/or fix you were hoping for. Note that all tests (including manually testing above) ran fine on macOS, but I did not test on OpenIndiana.

  2. serhiy-storchaka commented on Aug 26, 2025

    @serhiy-storchaka
    MemberAuthor

    This turned out to be more complicated than I thought.

    The following script:

    import threading
    import _thread
    
    def test(name):
        print('test', repr(name))
        print('<', repr(_thread._get_name()))
        try:
            _thread.set_name(name)
            print('>', repr(_thread._get_name()))
        except OSError as e:
            print('>', repr(e))
    
    test('main name')
    test('main nam€')
    
    t = threading.Thread(target=test, args=('set nam€',))
    t.start()
    t.join()
    
    t = threading.Thread(target=test, args=('set name',), name='init name')
    t.start()
    t.join()
    
    t = threading.Thread(target=test, args=('set nam€',), name='init nam€')
    t.start()
    t.join()

    produces an expected output on Linux:

    test 'main name'
    < 'python'
    > 'main name'
    test 'main nam€'
    < 'main name'
    > 'main nam€'
    test 'set nam€'
    < 'Thread-1 (test)'
    > 'set nam€'
    test 'set name'
    < 'init name'
    > 'set name'
    test 'set nam€'
    < 'init nam€'
    > 'set nam€'
    

    But on OpenIndiana it is:

    test 'main name'
    < ''
    > 'main name'
    test 'main nam€'
    < 'main name'
    > OSError(22, 'Invalid argument')
    test 'set nam€'
    < 'Thread-1 (test)'
    > 'Thread-1 (test)'
    test 'set name'
    < 'init name'
    > 'set name'
    test 'set nam€'
    < ''
    > ''
    

    Setting a non-ASCII name does not work in the main thread and has no effect in other threads. Setting an ASCII name works in all cases.

    Adding a fallback in _thread.set_name() only affects the main thread and does not help to solve the problem with tests.

  3. changed the title [-]test_set_name fails on OpenIndiana (and Solaris?)[/-] [+]test_set_name fails on OpenIndiana[/+] on Aug 27, 2025
  4. serhiy-storchaka commented on Sep 1, 2025

    @serhiy-storchaka
    MemberAuthor

    Since pthread_setname_np() on OpenIndiana does nor return error, but silently does nothing, the only way to check this its to call pthread_getname_np() and compare the result with new name. But this is too much hassle.

    A simpler solution is just always use ASCII on OpenIndiana. This is less generic, and we can miss when they fix this, but this is the simplest solution.

    We need to add also a test for the main thread with non-ASCII name.

  5. vstinner commented on Sep 1, 2025

    @vstinner
    Member

    In C, is there a way to detect OpenIndiana with a macro? If not, sadly, I would suggest to always use ASCII/replace on Solaris and OpenIndiana.

  6. jadonduff commented on Sep 2, 2025

    @jadonduff
    Contributor

    @vstinner I could not find a way to detect OpenIndiana with a macro in C (more specifically, differentiate it from other solaris/illumos platforms), so my new changes simply always use ASCII/replace on Solaris and OpenIndiana. If anyone does know of a way, let me know and we can change it.

  7. added a commit that references this issue on Sep 2, 2025
  8. added a commit that references this issue on Sep 2, 2025
  9. serhiy-storchaka commented on Sep 3, 2025

    @serhiy-storchaka
    MemberAuthor

    Thank you for your contribution @jadonduff.

  10. added a commit that references this issue on Sep 9, 2025
  11. added a commit that references this issue on Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15bugs and security fixesOS-unsupportedextension-modulesC modules in the Modules dirtestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions