STINNER Victor <[email protected]> added the comment:
sigprocmask or (better) pthread_sigmask is required to fix #11859 bug.
---
Python has a test for "broken pthread_sigmask". Extract of configure.in:
AC_MSG_CHECKING(if PTHREAD_SCOPE_SYSTEM is supported)
AC_CACHE_VAL(ac_cv_pthread_system_supported,
[AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <pthread.h>
void *foo(void *parm) {
return NULL;
}
main() {
pthread_attr_t attr;
pthread_t id;
if (pthread_attr_init(&attr)) exit(-1);
if (pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM)) exit(-1);
if (pthread_create(&id, &attr, foo, NULL)) exit(-1);
exit(0);
}]])],
[ac_cv_pthread_system_supported=yes],
[ac_cv_pthread_system_supported=no],
[ac_cv_pthread_system_supported=no])
])
AC_MSG_RESULT($ac_cv_pthread_system_supported)
if test "$ac_cv_pthread_system_supported" = "yes"; then
AC_DEFINE(PTHREAD_SYSTEM_SCHED_SUPPORTED, 1, [Defined if
PTHREAD_SCOPE_SYSTEM supported.])
fi
AC_CHECK_FUNCS(pthread_sigmask,
[case $ac_sys_system in
CYGWIN*)
AC_DEFINE(HAVE_BROKEN_PTHREAD_SIGMASK, 1,
[Define if pthread_sigmask() does not work on your system.])
;;
esac])
Extract of Python/thread_pthread.h:
/* On platforms that don't use standard POSIX threads pthread_sigmask()
* isn't present. DEC threads uses sigprocmask() instead as do most
* other UNIX International compliant systems that don't have the full
* pthread implementation.
*/
#if defined(HAVE_PTHREAD_SIGMASK) && !defined(HAVE_BROKEN_PTHREAD_SIGMASK)
# define SET_THREAD_SIGMASK pthread_sigmask
#else
# define SET_THREAD_SIGMASK sigprocmask
#endif
---
Because today more and more programs rely on threads, it is maybe not a good
idea to provide a binding of sigprocmask(). I would prefer to only add
pthread_sigmask() which has a determistic behaviour with threads. So only
compile signal.pthread_sigmask() if pthread API is present and pthread_sigmask
"is not broken".
---
About the patch: the doc should explain that the signal masks are inherited for
child processes (fork() and execve()). I don't know if this behaviour is
specific to Linux or not.
If we only use pthread_sigmask(), the doc is wrong: "Set the signal mask for
the process." It's not for the process but only for the current thread.
How does it work if I change the signal mask of the main thread and then I
create a new thread: the signal mask is inherited, or a default mask is used
instead?
---
The new faulthandler uses a thread to implement a timeout: the thread uses
pthread_sigmask() or sigprocmask() to ignore all signals. If I don't set the
signal mask, some tests fail: check that a system call (like reading from a
pipe) can be interrupted by signal. The problem is that signal may be send to
the faulthandler thread, instead of the main thread. Hum, while I'm writing
this, I realize that I should maybe not fallback to sigprocmask() because it
may mask signals for the whole process (all threads)!
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue8407>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com