gh-59705: Export threading.Thread() names to the OS#14578
gh-59705: Export threading.Thread() names to the OS#14578ZackerySpytz wants to merge 1 commit intopython:mainfrom
Conversation
Call pthread_setname_np() et al. with the name argument passed to threading.Thread().
|
Unfortunately, the string passed to |
|
Will this ever happen?! The Issue has this year the 10th anniversary. In the Issue @eryksun also provides Code for Windows... so let this happen. |
| if _HAVE_THREAD_NATIVE_ID: | ||
| self._set_native_id() | ||
| if _HAVE_SET_THREAD_NAME: | ||
| _set_thread_name(self.name) |
There was a problem hiding this comment.
This should probably be more sophisticated, e.g. f"{sys.executable} [thread {self.name!r}]"
There was a problem hiding this comment.
That wouldn't work well for platforms with the 16-character limitation.
|
I would expect to see some changes to the Docs, how use, and if any affect on whats out there running now. Probably need to add version changed. |
encukou
left a comment
There was a problem hiding this comment.
This needs tests, which in turn will need a getter function -- at least a private one.
| int ret = 0; | ||
| #ifdef __APPLE__ | ||
| // On macOS, pthread_setname_np() can only set the calling thread's name. | ||
| ret = pthread_setname_np(buf); |
There was a problem hiding this comment.
It seems (from the man page) that macOS doesn't have the 16-character limitation. Could we pass the original buffer here?
| if _HAVE_THREAD_NATIVE_ID: | ||
| self._set_native_id() | ||
| if _HAVE_SET_THREAD_NAME: | ||
| _set_thread_name(self.name) |
There was a problem hiding this comment.
That wouldn't work well for platforms with the 16-character limitation.
|
New attempt to implement this feature: #127338 |
|
#127338 was merged instead. Thanks for your contribution anyway! |
Call pthread_setname_np() et al. with the name argument passed to
threading.Thread().
https://bugs.python.org/issue15500