Send an object to the other end of the connection which should be read
using :meth:`recv`.
- The object must be picklable.
+ The object must be picklable. Very large pickles (approximately 32 MB+,
+ though it depends on the OS) may raise a ValueError exception.
.. method:: recv()
complete message.
If *offset* is given then data is read from that position in *buffer*. If
- *size* is given then that many bytes will be read from buffer.
+ *size* is given then that many bytes will be read from buffer. Very large
+ buffers (approximately 32 MB+, though it depends on the OS) may raise a
+ ValueError exception
.. method:: recv_bytes([maxlength])
.. class:: Event()
A clone of :class:`threading.Event`.
+ This method returns the state of the internal semaphore on exit, so it
+ will always return ``True`` except if a timeout is given and the operation
+ times out.
+
+ .. versionchanged:: 2.7
+ Previously, the method always returned ``None``.
.. class:: Lock()
self._flag.release()
else:
self._cond.wait(timeout)
+
+ if self._flag.acquire(False):
+ self._flag.release()
+ return True
+ return False
finally:
self._cond.release()
# Removed temporaily, due to API shear, this does not
# work with threading._Event objects. is_set == isSet
- #self.assertEqual(event.is_set(), False)
+ self.assertEqual(event.is_set(), False)
- self.assertEqual(wait(0.0), None)
+ # Removed, threading.Event.wait() will return the value of the __flag
+ # instead of None. API Shear with the semaphore backed mp.Event
+ self.assertEqual(wait(0.0), False)
self.assertTimingAlmostEqual(wait.elapsed, 0.0)
- self.assertEqual(wait(TIMEOUT1), None)
+ self.assertEqual(wait(TIMEOUT1), False)
self.assertTimingAlmostEqual(wait.elapsed, TIMEOUT1)
event.set()
# See note above on the API differences
- # self.assertEqual(event.is_set(), True)
- self.assertEqual(wait(), None)
+ self.assertEqual(event.is_set(), True)
+ self.assertEqual(wait(), True)
self.assertTimingAlmostEqual(wait.elapsed, 0.0)
- self.assertEqual(wait(TIMEOUT1), None)
+ self.assertEqual(wait(TIMEOUT1), True)
self.assertTimingAlmostEqual(wait.elapsed, 0.0)
# self.assertEqual(event.is_set(), True)
#self.assertEqual(event.is_set(), False)
self.Process(target=self._test_event, args=(event,)).start()
- self.assertEqual(wait(), None)
+ self.assertEqual(wait(), True)
#
#
res = conn_send_string(self, buffer + offset, size);
PyBuffer_Release(&pbuffer);
- if (res < 0)
- return mp_SetError(PyExc_IOError, res);
+ if (res < 0) {
+ if (PyErr_Occurred())
+ return NULL;
+ else
+ return mp_SetError(PyExc_IOError, res);
+ }
Py_RETURN_NONE;
}
#include "multiprocessing.h"
+#ifdef SCM_RIGHTS
+ #define HAVE_FD_TRANSFER 1
+#else
+ #define HAVE_FD_TRANSFER 0
+#endif
+
PyObject *create_win32_namespace(void);
PyObject *pickle_dumps, *pickle_loads, *pickle_protocol;
Py_INCREF(&ConnectionType);
PyModule_AddObject(module, "Connection", (PyObject*)&ConnectionType);
-#if defined(MS_WINDOWS) || HAVE_SEM_OPEN
+#if defined(MS_WINDOWS) || defined(HAVE_SEM_OPEN)
/* Add SemLock type to module */
if (PyType_Ready(&SemLockType) < 0)
return NULL;
# include <sys/socket.h>
# include <sys/uio.h>
# include <arpa/inet.h> /* htonl() and ntohl() */
-# if HAVE_SEM_OPEN
+# ifdef HAVE_SEM_OPEN
# include <semaphore.h>
typedef sem_t *SEM_HANDLE;
# endif
* Issue 3110 - Solaris does not define SEM_VALUE_MAX
*/
#ifndef SEM_VALUE_MAX
-# ifdef _SEM_VALUE_MAX
-# define SEM_VALUE_MAX _SEM_VALUE_MAX
-# else
-# define SEM_VALUE_MAX INT_MAX
-# endif
+ #if defined(HAVE_SYSCONF) && defined(_SC_SEM_VALUE_MAX)
+ # define SEM_VALUE_MAX sysconf(_SC_SEM_VALUE_MAX)
+ #elif defined(_SEM_VALUE_MAX)
+ # define SEM_VALUE_MAX _SEM_VALUE_MAX
+ #elif definef(_POSIX_SEM_VALUE_MAX)
+ # define SEM_VALUE_MAX _POSIX_SEM_VALUE_MAX
+ #else
+ # define SEM_VALUE_MAX INT_MAX
+ #endif
#endif
+
/*
* Make sure Py_ssize_t available
*/
Py_BEGIN_ALLOW_THREADS
ret = WriteFile(conn->handle, string, length, &amount_written, NULL);
Py_END_ALLOW_THREADS
+
+ if (ret == 0 && GetLastError() == ERROR_NO_SYSTEM_RESOURCES) {
+ PyErr_Format(PyExc_ValueError, "Cannnot send %" PY_FORMAT_SIZE_T "d bytes over connection", length);
+ return MP_STANDARD_ERROR;
+ }
+
return ret ? MP_SUCCESS : MP_STANDARD_ERROR;
}
#define SEM_GETVALUE(sem, pval) sem_getvalue(sem, pval)
#define SEM_UNLINK(name) sem_unlink(name)
-#if HAVE_BROKEN_SEM_UNLINK
+#ifndef HAVE_SEM_UNLINK
# define sem_unlink(name) 0
#endif
-#if !HAVE_SEM_TIMEDWAIT
+#ifndef HAVE_SEM_TIMEDWAIT
# define sem_timedwait(sem,deadline) sem_timedwait_save(sem,deadline,_save)
int
}
assert(self->count == 1);
} else {
-#if HAVE_BROKEN_SEM_GETVALUE
+#ifdef HAVE_BROKEN_SEM_GETVALUE
/* We will only check properly the maxvalue == 1 case */
if (self->maxvalue == 1) {
/* make sure that already locked */
static PyObject *
semlock_getvalue(SemLockObject *self)
{
-#if HAVE_BROKEN_SEM_GETVALUE
+#ifdef HAVE_BROKEN_SEM_GETVALUE
PyErr_SetNone(PyExc_NotImplementedError);
return NULL;
#else
static PyObject *
semlock_iszero(SemLockObject *self)
{
-#if HAVE_BROKEN_SEM_GETVALUE
+#ifdef HAVE_BROKEN_SEM_GETVALUE
if (sem_trywait(self->handle) < 0) {
if (errno == EAGAIN)
Py_RETURN_TRUE;
#! /bin/sh
-# From configure.in Revision: 70732 .
+# From configure.in Revision: 71261 .
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.61 for python 3.1.
#
+
+
+
+
kill killpg lchmod lchown lstat mkfifo mknod mktime \
mremap nice pathconf pause plock poll pthread_init \
putenv readlink realpath \
- select setegid seteuid setgid \
+ select sem_open sem_timedwait sem_getvalue sem_unlink setegid seteuid \
+ setgid \
setlocale setregid setreuid setsid setpgid setpgrp setuid setvbuf snprintf \
sigaction siginterrupt sigrelse strftime strlcpy \
sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
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; }
+if test "$cross_compiling" = yes; then
+ { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot run test program while cross compiling
+See \`config.log' for more details." >&2;}
+ { (exit 1); exit 1; }; }
+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);
+ int count;
+ int res;
+ if(a==SEM_FAILED){
+ perror("sem_open");
+ return 1;
+
+ }
+ res = sem_getvalue(a, &count);
+ sem_close(a);
+ return res==-1 ? 1 : 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
+ { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+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 )
+{ echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_BROKEN_SEM_GETVALUE 1
+_ACEOF
+
+
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+
+
# On FreeBSD 6.2, it appears that tanh(-0.) returns 0. instead of
# -0. on some architectures.
kill killpg lchmod lchown lstat mkfifo mknod mktime \
mremap nice pathconf pause plock poll pthread_init \
putenv readlink realpath \
- select setegid seteuid setgid \
+ select sem_open sem_timedwait sem_getvalue sem_unlink setegid seteuid \
+ setgid \
setlocale setregid setreuid setsid setpgid setpgrp setuid setvbuf snprintf \
sigaction siginterrupt sigrelse strftime strlcpy \
sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
[Define if arithmetic is subject to x87-style double rounding issue])
fi
+# Multiprocessing check for broken sem_getvalue
+AC_MSG_CHECKING(for broken sem_getvalue)
+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);
+ int count;
+ int res;
+ if(a==SEM_FAILED){
+ perror("sem_open");
+ return 1;
+
+ }
+ res = sem_getvalue(a, &count);
+ sem_close(a);
+ return res==-1 ? 1 : 0;
+}
+]
+,AC_MSG_RESULT(no),
+ AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_BROKEN_SEM_GETVALUE, 1, define to 1 if your sem_getvalue is broken.)
+)
# On FreeBSD 6.2, it appears that tanh(-0.) returns 0. instead of
# -0. on some architectures.
/* Define if pthread_sigmask() does not work on your system. */
#undef HAVE_BROKEN_PTHREAD_SIGMASK
+/* define to 1 if your sem_getvalue is broken. */
+#undef HAVE_BROKEN_SEM_GETVALUE
+
/* Define this if you have the type _Bool. */
#undef HAVE_C99_BOOL
/* Define to 1 if you have the `select' function. */
#undef HAVE_SELECT
+/* Define to 1 if you have the `sem_getvalue' function. */
+#undef HAVE_SEM_GETVALUE
+
+/* Define to 1 if you have the `sem_open' function. */
+#undef HAVE_SEM_OPEN
+
+/* Define to 1 if you have the `sem_timedwait' function. */
+#undef HAVE_SEM_TIMEDWAIT
+
+/* Define to 1 if you have the `sem_unlink' function. */
+#undef HAVE_SEM_UNLINK
+
/* Define to 1 if you have the `setegid' function. */
#undef HAVE_SETEGID
libraries = ['ws2_32']
elif platform == 'darwin': # Mac OSX
- macros = dict(
- HAVE_SEM_OPEN=1,
- HAVE_SEM_TIMEDWAIT=0,
- HAVE_FD_TRANSFER=1,
- HAVE_BROKEN_SEM_GETVALUE=1
- )
+ macros = dict()
libraries = []
elif platform == 'cygwin': # Cygwin
- macros = dict(
- HAVE_SEM_OPEN=1,
- HAVE_SEM_TIMEDWAIT=1,
- HAVE_FD_TRANSFER=0,
- HAVE_BROKEN_SEM_UNLINK=1
- )
+ macros = dict()
libraries = []
elif platform in ('freebsd4', 'freebsd5', 'freebsd6', 'freebsd7', 'freebsd8'):
# FreeBSD's P1003.1b semaphore support is very experimental
# and has many known problems. (as of June 2008)
- macros = dict( # FreeBSD
- HAVE_SEM_OPEN=0,
- HAVE_SEM_TIMEDWAIT=0,
- HAVE_FD_TRANSFER=1,
- )
+ macros = dict()
libraries = []
elif platform.startswith('openbsd'):
- macros = dict( # OpenBSD
- HAVE_SEM_OPEN=0, # Not implemented
- HAVE_SEM_TIMEDWAIT=0,
- HAVE_FD_TRANSFER=1,
- )
+ macros = dict()
libraries = []
elif platform.startswith('netbsd'):
- macros = dict( # at least NetBSD 5
- HAVE_SEM_OPEN=1,
- HAVE_SEM_TIMEDWAIT=0,
- HAVE_FD_TRANSFER=1,
- HAVE_BROKEN_SEM_GETVALUE=1
- )
+ macros = dict()
libraries = []
else: # Linux and other unices
- macros = dict(
- HAVE_SEM_OPEN=1,
- HAVE_SEM_TIMEDWAIT=1,
- HAVE_FD_TRANSFER=1
- )
+ macros = dict()
libraries = ['rt']
if platform == 'win32':
multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c',
'_multiprocessing/socket_connection.c'
]
-
- if macros.get('HAVE_SEM_OPEN', False):
+ if sysconfig.get_config_var('HAVE_SEM_OPEN'):
multiprocessing_srcs.append('_multiprocessing/semaphore.c')
if sysconfig.get_config_var('WITH_THREAD'):