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:
Victor Stinner
2024-12-06 17:27:12 +01:00
committed by GitHub
parent 12680ec5bd
commit 67b18a18b6
8 changed files with 342 additions and 2 deletions

30
configure generated vendored
View File

@@ -821,6 +821,7 @@ MODULE_TIME_TRUE
MODULE__IO_FALSE
MODULE__IO_TRUE
MODULE_BUILDTYPE
PYTHREAD_NAME_MAXLEN
TEST_MODULES
OPENSSL_LDFLAGS
OPENSSL_LIBS
@@ -18841,6 +18842,18 @@ if test "x$ac_cv_func_pthread_kill" = xyes
then :
printf "%s\n" "#define HAVE_PTHREAD_KILL 1" >>confdefs.h
fi
ac_fn_c_check_func "$LINENO" "pthread_getname_np" "ac_cv_func_pthread_getname_np"
if test "x$ac_cv_func_pthread_getname_np" = xyes
then :
printf "%s\n" "#define HAVE_PTHREAD_GETNAME_NP 1" >>confdefs.h
fi
ac_fn_c_check_func "$LINENO" "pthread_setname_np" "ac_cv_func_pthread_setname_np"
if test "x$ac_cv_func_pthread_setname_np" = xyes
then :
printf "%s\n" "#define HAVE_PTHREAD_SETNAME_NP 1" >>confdefs.h
fi
ac_fn_c_check_func "$LINENO" "ptsname" "ac_cv_func_ptsname"
if test "x$ac_cv_func_ptsname" = xyes
@@ -29081,6 +29094,23 @@ fi
CPPFLAGS=$save_CPPFLAGS
# gh-59705: Maximum length in bytes of a thread name
case "$ac_sys_system" in
Linux*) PYTHREAD_NAME_MAXLEN=15;; # Linux and Android
SunOS*) PYTHREAD_NAME_MAXLEN=31;;
Darwin) PYTHREAD_NAME_MAXLEN=63;;
iOS) PYTHREAD_NAME_MAXLEN=63;;
FreeBSD*) PYTHREAD_NAME_MAXLEN=98;;
*) PYTHREAD_NAME_MAXLEN=;;
esac
if test -n "$PYTHREAD_NAME_MAXLEN"; then
printf "%s\n" "#define PYTHREAD_NAME_MAXLEN $PYTHREAD_NAME_MAXLEN" >>confdefs.h
fi
# stdlib