mirror of
https://github.com/python/cpython.git
synced 2025-11-01 14:11:41 +00:00
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>
This commit is contained in:
parent
12680ec5bd
commit
67b18a18b6
8 changed files with 342 additions and 2 deletions
|
|
@ -48,6 +48,10 @@
|
|||
__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 @@ def _bootstrap_inner(self):
|
|||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue