Skip to content
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

Closed

Conversation

ZackerySpytz
Copy link
Contributor

@ZackerySpytz ZackerySpytz commented Jul 3, 2019

Call pthread_setname_np() et al. with the name argument passed to
threading.Thread().

https://bugs.python.org/issue15500

Call pthread_setname_np() et al. with the name argument passed to
threading.Thread().
@ZackerySpytz
Copy link
Contributor Author

Unfortunately, the string passed to pthread_setname_np() must be less than 16 chars on Linux, so the name may be truncated.

@debauer
Copy link

debauer commented Jan 18, 2022

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)
Copy link
Member

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}]"

Copy link
Member

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.

@MaxwellDupre
Copy link
Contributor

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.

@erlend-aasland erlend-aasland changed the title bpo-15500: Export threading.Thread() names to the OS gh-59705: Export threading.Thread() names to the OS Jan 5, 2024
Copy link
Member

@encukou encukou left a 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);
Copy link
Member

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)
Copy link
Member

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.

@vstinner
Copy link
Member

New attempt to implement this feature: #127338

@vstinner
Copy link
Member

vstinner commented Dec 6, 2024

#127338 was merged instead. Thanks for your contribution anyway!

@vstinner vstinner closed this Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants