diff options
author | Victor Stinner <vstinner@python.org> | 2024-12-06 17:27:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-06 16:27:12 +0000 |
commit | 67b18a18b66b89e253f38895057ef9f6bae92e7b (patch) | |
tree | 86d8e41e6935361b3821b7e2769553ca2123bf0d /Lib/threading.py | |
parent | 12680ec5bd45c85b6daebe0739d30ef45f089efa (diff) | |
download | cpython-67b18a18b66b89e253f38895057ef9f6bae92e7b.tar.gz cpython-67b18a18b66b89e253f38895057ef9f6bae92e7b.zip |
gh-59705: Add _thread.set_name() function (#127338)
On Linux, threading.Thread now sets the thread name to the operating
system.
* configure now checks if pthread_getname_np()
and pthread_setname_np() functions are available.
* Add PYTHREAD_NAME_MAXLEN macro.
* Add _thread._NAME_MAXLEN constant for test_threading.
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/threading.py')
-rw-r--r-- | Lib/threading.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/threading.py b/Lib/threading.py index 94ea2f08178..3abd22a2aa1 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -48,6 +48,10 @@ try: __all__.append('get_native_id') except AttributeError: _HAVE_THREAD_NATIVE_ID = False +try: + _set_name = _thread.set_name +except AttributeError: + _set_name = None ThreadError = _thread.error try: _CRLock = _thread.RLock @@ -1027,6 +1031,11 @@ class Thread: self._set_ident() if _HAVE_THREAD_NATIVE_ID: self._set_native_id() + if _set_name is not None and self._name: + try: + _set_name(self._name) + except OSError: + pass self._started.set() with _active_limbo_lock: _active[self._ident] = self |