| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Export :class:`threading.Thread` names to the OS. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -17,6 +17,7 @@ | |
| #elif defined(__FreeBSD__) | ||
| # include <pthread_np.h> /* pthread_getthreadid_np() */ | ||
| #elif defined(__OpenBSD__) | ||
| # include <pthread_np.h> | ||
| # include <unistd.h> /* getthrid() */ | ||
| #elif defined(_AIX) | ||
| # include <sys/thread.h> /* thread_self() */ | ||
| Expand Down Expand Up | @@ -343,6 +344,37 @@ PyThread_get_thread_native_id(void) | |
| } | ||
| #endif | ||
|
|
||
| #ifdef PY_HAVE_SET_THREAD_NAME | ||
| int | ||
| PyThread_set_thread_name(const char *name) | ||
| { | ||
| if (!initialized) { | ||
| PyThread_init_thread(); | ||
| } | ||
| // Truncate the string to 15 chars for pthread_setname_np(). | ||
| char buf[16]; | ||
| size_t len = Py_ARRAY_LENGTH(buf) - 1; | ||
| strncpy(buf, name, len); | ||
| buf[len] = '\0'; | ||
| #ifndef __APPLE__ | ||
| unsigned long ident = PyThread_get_thread_ident(); | ||
| #endif | ||
| int ret = 0; | ||
| #ifdef __APPLE__ | ||
| // On macOS, pthread_setname_np() can only set the calling thread's name. | ||
| ret = pthread_setname_np(buf); | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIt seems (from the man page) that macOS doesn't have the 16-character limitation. Could we pass the original buffer here?
Sorry, something went wrong.
All reactions
|
||
| #elif defined(__FreeBSD__) || defined(__OpenBSD__) | ||
| // No return value. | ||
| pthread_set_name_np((pthread_t)ident, buf); | ||
| #elif defined(__NetBSD__) | ||
| ret = pthread_setname_np((pthread_t)ident, "%s", (void *)buf); | ||
| #elif defined(__linux__) | ||
| ret = pthread_setname_np((pthread_t)ident, buf); | ||
| #endif | ||
| return ret; | ||
| } | ||
| #endif | ||
|
|
||
| void _Py_NO_RETURN | ||
| PyThread_exit_thread(void) | ||
| { | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis should probably be more sophisticated, e.g. f"{sys.executable} [thread {self.name!r}]"
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThat wouldn't work well for platforms with the 16-character limitation.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.