-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-59705: Export threading.Thread() names to the OS #14578
gh-59705: Export threading.Thread() names to the OS #14578
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. |
@@ -924,6 +929,8 @@ def _bootstrap_inner(self): | |||
self._set_tstate_lock() | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be more sophisticated, e.g. f"{sys.executable} [thread {self.name!r}]"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems (from the man page) that macOS doesn't have the 16-character limitation. Could we pass the original buffer here?
@@ -924,6 +929,8 @@ def _bootstrap_inner(self): | |||
self._set_tstate_lock() | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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