homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients benjamin.peterson, exarkun, gregory.p.smith, loewis, marcin.bachry, pitrou, schmichael, spiv, tseaver, vstinner
Date 2011年04月18日.16:00:15
SpamBayes Score 9.214851e-14
Marked as misclassified No
Message-id <1303142416.82.0.51113181918.issue8407@psf.upfronthosting.co.za>
In-reply-to
Content
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)!
History
Date User Action Args
2011年04月18日 16:00:17vstinnersetrecipients: + vstinner, loewis, gregory.p.smith, spiv, exarkun, tseaver, pitrou, benjamin.peterson, marcin.bachry, schmichael
2011年04月18日 16:00:16vstinnersetmessageid: <1303142416.82.0.51113181918.issue8407@psf.upfronthosting.co.za>
2011年04月18日 16:00:15vstinnerlinkissue8407 messages
2011年04月18日 16:00:15vstinnercreate

AltStyle によって変換されたページ (->オリジナル) /