[Python-checkins] r76432 - in python/trunk: Lib/test/test_multiprocessing.py Modules/_multiprocessing/multiprocessing.c Modules/_multiprocessing/multiprocessing.h configure configure.in setup.py

mark.dickinson python-checkins at python.org
Fri Nov 20 20:30:23 CET 2009


Author: mark.dickinson
Date: Fri Nov 20 20:30:22 2009
New Revision: 76432

Log:
Issue #7272:  Add configure test to detect whether sem_open works
properly, and use this to skip test_multiprocessing on platforms
where sem_open raises a signal.  This should fix some FreeBSD buildbot
failures for test_multiprocessing.


Modified:
   python/trunk/Lib/test/test_multiprocessing.py
   python/trunk/Modules/_multiprocessing/multiprocessing.c
   python/trunk/Modules/_multiprocessing/multiprocessing.h
   python/trunk/configure
   python/trunk/configure.in
   python/trunk/setup.py

Modified: python/trunk/Lib/test/test_multiprocessing.py
==============================================================================
--- python/trunk/Lib/test/test_multiprocessing.py	(original)
+++ python/trunk/Lib/test/test_multiprocessing.py	Fri Nov 20 20:30:22 2009
@@ -17,7 +17,7 @@
 import socket
 import random
 import logging
-import test_support
+from test import test_support
 from StringIO import StringIO
 
 

Modified: python/trunk/Modules/_multiprocessing/multiprocessing.c
==============================================================================
--- python/trunk/Modules/_multiprocessing/multiprocessing.c	(original)
+++ python/trunk/Modules/_multiprocessing/multiprocessing.c	Fri Nov 20 20:30:22 2009
@@ -250,7 +250,8 @@
 	Py_INCREF(&ConnectionType);	
 	PyModule_AddObject(module, "Connection", (PyObject*)&ConnectionType);
 
-#if defined(MS_WINDOWS) || defined(HAVE_SEM_OPEN)
+#if defined(MS_WINDOWS) ||						\
+  (defined(HAVE_SEM_OPEN) && !defined(HAVE_BROKEN_POSIX_SEMAPHORES))
 	/* Add SemLock type to module */
 	if (PyType_Ready(&SemLockType) < 0)
 		return;
@@ -297,7 +298,7 @@
 		Py_DECREF(temp); Py_DECREF(value); return; }	  \
 	Py_DECREF(value)
 	
-#ifdef HAVE_SEM_OPEN
+#if defined(HAVE_SEM_OPEN) && !defined(HAVE_BROKEN_POSIX_SEMAPHORES)
 	ADD_FLAG(HAVE_SEM_OPEN);
 #endif
 #ifdef HAVE_SEM_TIMEDWAIT

Modified: python/trunk/Modules/_multiprocessing/multiprocessing.h
==============================================================================
--- python/trunk/Modules/_multiprocessing/multiprocessing.h	(original)
+++ python/trunk/Modules/_multiprocessing/multiprocessing.h	Fri Nov 20 20:30:22 2009
@@ -27,7 +27,7 @@
 #  include <sys/socket.h>
 #  include <sys/uio.h>
 #  include <arpa/inet.h>             /* htonl() and ntohl() */
-#  ifdef HAVE_SEM_OPEN
+#  if defined(HAVE_SEM_OPEN) && !defined(HAVE_BROKEN_POSIX_SEMAPHORES)
 #    include <semaphore.h>
      typedef sem_t *SEM_HANDLE;
 #  endif

Modified: python/trunk/configure
==============================================================================
--- python/trunk/configure	(original)
+++ python/trunk/configure	Fri Nov 20 20:30:22 2009
@@ -23782,6 +23782,91 @@
 LIBS_SAVE=$LIBS
 LIBS="$LIBS $LIBM"
 
+# For multiprocessing module, check that sem_open
+# actually works.  For FreeBSD versions <= 7.2,
+# the kernel module that provides POSIX semaphores
+# isn't loaded by default, so an attempt to call
+# sem_open results in a 'Signal 12' error.
+{ echo "$as_me:$LINENO: checking whether POSIX semaphores are enabled" >&5
+echo $ECHO_N "checking whether POSIX semaphores are enabled... $ECHO_C" >&6; }
+if test "${ac_cv_posix_semaphores_enabled+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test "$cross_compiling" = yes; then
+  ac_cv_posix_semaphores_enabled=yes
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <semaphore.h>
+#include <sys/stat.h>
+
+int main(void) {
+  sem_t *a = sem_open("/autoconf", O_CREAT, S_IRUSR|S_IWUSR, 0);
+  if (a == SEM_FAILED) {
+    perror("sem_open");
+    return 1;
+  }
+  sem_close(a);
+  return 0;
+}
+
+_ACEOF
+rm -f conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_posix_semaphores_enabled=yes
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+ac_cv_posix_semaphores_enabled=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+
+
+
+fi
+
+{ echo "$as_me:$LINENO: result: $ac_cv_posix_semaphores_enabled" >&5
+echo "${ECHO_T}$ac_cv_posix_semaphores_enabled" >&6; }
+if test $ac_cv_posix_semaphores_enabled = no
+then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_BROKEN_POSIX_SEMAPHORES 1
+_ACEOF
+
+fi
+
+
 # Multiprocessing check for broken sem_getvalue
 { echo "$as_me:$LINENO: checking for broken sem_getvalue" >&5
 echo $ECHO_N "checking for broken sem_getvalue... $ECHO_C" >&6; }

Modified: python/trunk/configure.in
==============================================================================
--- python/trunk/configure.in	(original)
+++ python/trunk/configure.in	Fri Nov 20 20:30:22 2009
@@ -3387,6 +3387,41 @@
 LIBS_SAVE=$LIBS
 LIBS="$LIBS $LIBM"
 
+# For multiprocessing module, check that sem_open
+# actually works.  For FreeBSD versions <= 7.2,
+# the kernel module that provides POSIX semaphores
+# isn't loaded by default, so an attempt to call
+# sem_open results in a 'Signal 12' error.
+AC_MSG_CHECKING(whether POSIX semaphores are enabled)
+AC_CACHE_VAL(ac_cv_posix_semaphores_enabled,
+AC_TRY_RUN([
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <semaphore.h>
+#include <sys/stat.h>
+
+int main(void) {
+  sem_t *a = sem_open("/autoconf", O_CREAT, S_IRUSR|S_IWUSR, 0);
+  if (a == SEM_FAILED) {
+    perror("sem_open");
+    return 1;
+  }
+  sem_close(a);
+  return 0;
+}
+], ac_cv_posix_semaphores_enabled=yes,
+   ac_cv_posix_semaphores_enabled=no,
+   ac_cv_posix_semaphores_enabled=yes)
+)
+AC_MSG_RESULT($ac_cv_posix_semaphores_enabled)
+if test $ac_cv_posix_semaphores_enabled = no
+then
+  AC_DEFINE(HAVE_BROKEN_POSIX_SEMAPHORES, 1,
+            [Define if the Posix semaphores do not work on your system])
+fi
+
+
 # Multiprocessing check for broken sem_getvalue
 AC_MSG_CHECKING(for broken sem_getvalue)
 AC_CACHE_VAL(ac_cv_broken_sem_getvalue,

Modified: python/trunk/setup.py
==============================================================================
--- python/trunk/setup.py	(original)
+++ python/trunk/setup.py	Fri Nov 20 20:30:22 2009
@@ -1315,7 +1315,8 @@
             multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c',
                                      '_multiprocessing/socket_connection.c'
                                    ]
-            if sysconfig.get_config_var('HAVE_SEM_OPEN'):
+            if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not
+                sysconfig.get_config_var('HAVE_BROKEN_POSIX_SEMAPHORES')):
                 multiprocessing_srcs.append('_multiprocessing/semaphore.c')
 
         if sysconfig.get_config_var('WITH_THREAD'):


More information about the Python-checkins mailing list