Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 965ce87

Browse files
committed
Merged revisions 70908,70939,71009,71022,71036 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r70908 | jesse.noller | 2009-03-31 17:20:35 -0500 (Tue, 31 Mar 2009) | 1 line Issue 5619: Pass MS CRT debug flags into subprocesses ........ r70939 | jesse.noller | 2009-03-31 22:45:50 -0500 (Tue, 31 Mar 2009) | 1 line Fix multiprocessing.event to match the new threading.Event API ........ r71009 | jesse.noller | 2009-04-01 19:03:28 -0500 (Wed, 01 Apr 2009) | 1 line issue5545: Switch to Autoconf for multiprocessing; special thanks to Martin Lowis for help ........ r71022 | jesse.noller | 2009-04-01 21:32:55 -0500 (Wed, 01 Apr 2009) | 1 line Issue 3110: Additional protection for SEM_VALUE_MAX on platforms, thanks to Martin Loewis ........ r71036 | jesse.noller | 2009-04-01 23:22:09 -0500 (Wed, 01 Apr 2009) | 1 line Issue 3551: Raise ValueError if the size causes ERROR_NO_SYSTEM_RESOURCES ........
1 parent 1cdd83c commit 965ce87

12 files changed

Lines changed: 198 additions & 61 deletions

File tree

Doc/library/multiprocessing.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,8 @@ Connection objects usually created using :func:`Pipe` -- see also
708708
Send an object to the other end of the connection which should be read
709709
using :meth:`recv`.
710710

711-
The object must be picklable.
711+
The object must be picklable. Very large pickles (approximately 32 MB+,
712+
though it depends on the OS) may raise a ValueError exception.
712713

713714
.. method:: recv()
714715

@@ -740,7 +741,9 @@ Connection objects usually created using :func:`Pipe` -- see also
740741
complete message.
741742

742743
If *offset* is given then data is read from that position in *buffer*. If
743-
*size* is given then that many bytes will be read from buffer.
744+
*size* is given then that many bytes will be read from buffer. Very large
745+
buffers (approximately 32 MB+, though it depends on the OS) may raise a
746+
ValueError exception
744747

745748
.. method:: recv_bytes([maxlength])
746749

@@ -834,6 +837,12 @@ object -- see :ref:`multiprocessing-managers`.
834837
.. class:: Event()
835838

836839
A clone of :class:`threading.Event`.
840+
This method returns the state of the internal semaphore on exit, so it
841+
will always return ``True`` except if a timeout is given and the operation
842+
times out.
843+
844+
.. versionchanged:: 2.7
845+
Previously, the method always returned ``None``.
837846

838847
.. class:: Lock()
839848

Lib/multiprocessing/synchronize.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,5 +301,10 @@ def wait(self, timeout=None):
301301
self._flag.release()
302302
else:
303303
self._cond.wait(timeout)
304+
305+
if self._flag.acquire(False):
306+
self._flag.release()
307+
return True
308+
return False
304309
finally:
305310
self._cond.release()

Lib/test/test_multiprocessing.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -750,20 +750,22 @@ def test_event(self):
750750

751751
# Removed temporaily, due to API shear, this does not
752752
# work with threading._Event objects. is_set == isSet
753-
#self.assertEqual(event.is_set(), False)
753+
self.assertEqual(event.is_set(), False)
754754

755-
self.assertEqual(wait(0.0), None)
755+
# Removed, threading.Event.wait() will return the value of the __flag
756+
# instead of None. API Shear with the semaphore backed mp.Event
757+
self.assertEqual(wait(0.0), False)
756758
self.assertTimingAlmostEqual(wait.elapsed, 0.0)
757-
self.assertEqual(wait(TIMEOUT1), None)
759+
self.assertEqual(wait(TIMEOUT1), False)
758760
self.assertTimingAlmostEqual(wait.elapsed, TIMEOUT1)
759761

760762
event.set()
761763

762764
# See note above on the API differences
763-
# self.assertEqual(event.is_set(), True)
764-
self.assertEqual(wait(), None)
765+
self.assertEqual(event.is_set(), True)
766+
self.assertEqual(wait(), True)
765767
self.assertTimingAlmostEqual(wait.elapsed, 0.0)
766-
self.assertEqual(wait(TIMEOUT1), None)
768+
self.assertEqual(wait(TIMEOUT1), True)
767769
self.assertTimingAlmostEqual(wait.elapsed, 0.0)
768770
# self.assertEqual(event.is_set(), True)
769771

@@ -772,7 +774,7 @@ def test_event(self):
772774
#self.assertEqual(event.is_set(), False)
773775

774776
self.Process(target=self._test_event, args=(event,)).start()
775-
self.assertEqual(wait(), None)
777+
self.assertEqual(wait(), True)
776778

777779
#
778780
#

Modules/_multiprocessing/connection.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,12 @@ connection_sendbytes(ConnectionObject *self, PyObject *args)
139139
res = conn_send_string(self, buffer + offset, size);
140140

141141
PyBuffer_Release(&pbuffer);
142-
if (res < 0)
143-
return mp_SetError(PyExc_IOError, res);
142+
if (res < 0) {
143+
if (PyErr_Occurred())
144+
return NULL;
145+
else
146+
return mp_SetError(PyExc_IOError, res);
147+
}
144148

145149
Py_RETURN_NONE;
146150
}

Modules/_multiprocessing/multiprocessing.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
#include "multiprocessing.h"
1010

11+
#ifdef SCM_RIGHTS
12+
#define HAVE_FD_TRANSFER 1
13+
#else
14+
#define HAVE_FD_TRANSFER 0
15+
#endif
16+
1117
PyObject *create_win32_namespace(void);
1218

1319
PyObject *pickle_dumps, *pickle_loads, *pickle_protocol;
@@ -257,7 +263,7 @@ PyInit__multiprocessing(void)
257263
Py_INCREF(&ConnectionType);
258264
PyModule_AddObject(module, "Connection", (PyObject*)&ConnectionType);
259265

260-
#if defined(MS_WINDOWS) || HAVE_SEM_OPEN
266+
#if defined(MS_WINDOWS) || defined(HAVE_SEM_OPEN)
261267
/* Add SemLock type to module */
262268
if (PyType_Ready(&SemLockType) < 0)
263269
return NULL;

Modules/_multiprocessing/multiprocessing.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# include <sys/socket.h>
2828
# include <sys/uio.h>
2929
# include <arpa/inet.h> /* htonl() and ntohl() */
30-
# if HAVE_SEM_OPEN
30+
# ifdef HAVE_SEM_OPEN
3131
# include <semaphore.h>
3232
typedef sem_t *SEM_HANDLE;
3333
# endif
@@ -45,13 +45,18 @@
4545
* Issue 3110 - Solaris does not define SEM_VALUE_MAX
4646
*/
4747
#ifndef SEM_VALUE_MAX
48-
# ifdef _SEM_VALUE_MAX
49-
# define SEM_VALUE_MAX _SEM_VALUE_MAX
50-
# else
51-
# define SEM_VALUE_MAX INT_MAX
52-
# endif
48+
#if defined(HAVE_SYSCONF) && defined(_SC_SEM_VALUE_MAX)
49+
# define SEM_VALUE_MAX sysconf(_SC_SEM_VALUE_MAX)
50+
#elif defined(_SEM_VALUE_MAX)
51+
# define SEM_VALUE_MAX _SEM_VALUE_MAX
52+
#elif definef(_POSIX_SEM_VALUE_MAX)
53+
# define SEM_VALUE_MAX _POSIX_SEM_VALUE_MAX
54+
#else
55+
# define SEM_VALUE_MAX INT_MAX
56+
#endif
5357
#endif
5458

59+
5560
/*
5661
* Make sure Py_ssize_t available
5762
*/

Modules/_multiprocessing/pipe_connection.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ conn_send_string(ConnectionObject *conn, char *string, size_t length)
2323
Py_BEGIN_ALLOW_THREADS
2424
ret = WriteFile(conn->handle, string, length, &amount_written, NULL);
2525
Py_END_ALLOW_THREADS
26+
27+
if (ret == 0 && GetLastError() == ERROR_NO_SYSTEM_RESOURCES) {
28+
PyErr_Format(PyExc_ValueError, "Cannnot send %" PY_FORMAT_SIZE_T "d bytes over connection", length);
29+
return MP_STANDARD_ERROR;
30+
}
31+
2632
return ret ? MP_SUCCESS : MP_STANDARD_ERROR;
2733
}
2834

Modules/_multiprocessing/semaphore.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,11 @@ semlock_release(SemLockObject *self, PyObject *args)
197197
#define SEM_GETVALUE(sem, pval) sem_getvalue(sem, pval)
198198
#define SEM_UNLINK(name) sem_unlink(name)
199199

200-
#if HAVE_BROKEN_SEM_UNLINK
200+
#ifndef HAVE_SEM_UNLINK
201201
# define sem_unlink(name) 0
202202
#endif
203203

204-
#if !HAVE_SEM_TIMEDWAIT
204+
#ifndef HAVE_SEM_TIMEDWAIT
205205
# define sem_timedwait(sem,deadline) sem_timedwait_save(sem,deadline,_save)
206206

207207
int
@@ -348,7 +348,7 @@ semlock_release(SemLockObject *self, PyObject *args)
348348
}
349349
assert(self->count == 1);
350350
} else {
351-
#if HAVE_BROKEN_SEM_GETVALUE
351+
#ifdef HAVE_BROKEN_SEM_GETVALUE
352352
/* We will only check properly the maxvalue == 1 case */
353353
if (self->maxvalue == 1) {
354354
/* make sure that already locked */
@@ -494,7 +494,7 @@ semlock_ismine(SemLockObject *self)
494494
static PyObject *
495495
semlock_getvalue(SemLockObject *self)
496496
{
497-
#if HAVE_BROKEN_SEM_GETVALUE
497+
#ifdef HAVE_BROKEN_SEM_GETVALUE
498498
PyErr_SetNone(PyExc_NotImplementedError);
499499
return NULL;
500500
#else
@@ -512,7 +512,7 @@ semlock_getvalue(SemLockObject *self)
512512
static PyObject *
513513
semlock_iszero(SemLockObject *self)
514514
{
515-
#if HAVE_BROKEN_SEM_GETVALUE
515+
#ifdef HAVE_BROKEN_SEM_GETVALUE
516516
if (sem_trywait(self->handle) < 0) {
517517
if (errno == EAGAIN)
518518
Py_RETURN_TRUE;

configure

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /bin/sh
2-
# From configure.in Revision: 70732 .
2+
# From configure.in Revision: 71261 .
33
# Guess values for system-dependent variables and create Makefiles.
44
# Generated by GNU Autoconf 2.61 for python 3.1.
55
#
@@ -16259,6 +16259,10 @@ echo "${ECHO_T}MACHDEP_OBJS" >&6; }
1625916259

1626016260

1626116261

16262+
16263+
16264+
16265+
1626216266

1626316267

1626416268

@@ -16271,7 +16275,8 @@ for ac_func in alarm setitimer getitimer bind_textdomain_codeset chown \
1627116275
kill killpg lchmod lchown lstat mkfifo mknod mktime \
1627216276
mremap nice pathconf pause plock poll pthread_init \
1627316277
putenv readlink realpath \
16274-
select setegid seteuid setgid \
16278+
select sem_open sem_timedwait sem_getvalue sem_unlink setegid seteuid \
16279+
setgid \
1627516280
setlocale setregid setreuid setsid setpgid setpgrp setuid setvbuf snprintf \
1627616281
sigaction siginterrupt sigrelse strftime strlcpy \
1627716282
sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
@@ -21692,6 +21697,86 @@ _ACEOF
2169221697

2169321698
fi
2169421699

21700+
# Multiprocessing check for broken sem_getvalue
21701+
{ echo "$as_me:$LINENO: checking for broken sem_getvalue" >&5
21702+
echo $ECHO_N "checking for broken sem_getvalue... $ECHO_C" >&6; }
21703+
if test "$cross_compiling" = yes; then
21704+
{ { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
21705+
See \`config.log' for more details." >&5
21706+
echo "$as_me: error: cannot run test program while cross compiling
21707+
See \`config.log' for more details." >&2;}
21708+
{ (exit 1); exit 1; }; }
21709+
else
21710+
cat >conftest.$ac_ext <<_ACEOF
21711+
/* confdefs.h. */
21712+
_ACEOF
21713+
cat confdefs.h >>conftest.$ac_ext
21714+
cat >>conftest.$ac_ext <<_ACEOF
21715+
/* end confdefs.h. */
21716+
21717+
#include <unistd.h>
21718+
#include <fcntl.h>
21719+
#include <stdio.h>
21720+
#include <semaphore.h>
21721+
#include <sys/stat.h>
21722+
21723+
int main(void){
21724+
sem_t *a = sem_open("/autoconf", O_CREAT, S_IRUSR|S_IWUSR, 0);
21725+
int count;
21726+
int res;
21727+
if(a==SEM_FAILED){
21728+
perror("sem_open");
21729+
return 1;
21730+
21731+
}
21732+
res = sem_getvalue(a, &count);
21733+
sem_close(a);
21734+
return res==-1 ? 1 : 0;
21735+
}
21736+
21737+
21738+
_ACEOF
21739+
rm -f conftest$ac_exeext
21740+
if { (ac_try="$ac_link"
21741+
case "(($ac_try" in
21742+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
21743+
*) ac_try_echo=$ac_try;;
21744+
esac
21745+
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
21746+
(eval "$ac_link") 2>&5
21747+
ac_status=$?
21748+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
21749+
(exit $ac_status); } && { ac_try='./conftest$ac_exeext'
21750+
{ (case "(($ac_try" in
21751+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
21752+
*) ac_try_echo=$ac_try;;
21753+
esac
21754+
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
21755+
(eval "$ac_try") 2>&5
21756+
ac_status=$?
21757+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
21758+
(exit $ac_status); }; }; then
21759+
{ echo "$as_me:$LINENO: result: no" >&5
21760+
echo "${ECHO_T}no" >&6; }
21761+
else
21762+
echo "$as_me: program exited with status $ac_status" >&5
21763+
echo "$as_me: failed program was:" >&5
21764+
sed 's/^/| /' conftest.$ac_ext >&5
21765+
21766+
( exit $ac_status )
21767+
{ echo "$as_me:$LINENO: result: yes" >&5
21768+
echo "${ECHO_T}yes" >&6; }
21769+
21770+
cat >>confdefs.h <<\_ACEOF
21771+
#define HAVE_BROKEN_SEM_GETVALUE 1
21772+
_ACEOF
21773+
21774+
21775+
fi
21776+
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
21777+
fi
21778+
21779+
2169521780

2169621781
# On FreeBSD 6.2, it appears that tanh(-0.) returns 0. instead of
2169721782
# -0. on some architectures.

configure.in

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2388,7 +2388,8 @@ AC_CHECK_FUNCS(alarm setitimer getitimer bind_textdomain_codeset chown \
23882388
kill killpg lchmod lchown lstat mkfifo mknod mktime \
23892389
mremap nice pathconf pause plock poll pthread_init \
23902390
putenv readlink realpath \
2391-
select setegid seteuid setgid \
2391+
select sem_open sem_timedwait sem_getvalue sem_unlink setegid seteuid \
2392+
setgid \
23922393
setlocale setregid setreuid setsid setpgid setpgrp setuid setvbuf snprintf \
23932394
sigaction siginterrupt sigrelse strftime strlcpy \
23942395
sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
@@ -3108,6 +3109,33 @@ then
31083109
[Define if arithmetic is subject to x87-style double rounding issue])
31093110
fi
31103111

3112+
# Multiprocessing check for broken sem_getvalue
3113+
AC_MSG_CHECKING(for broken sem_getvalue)
3114+
AC_TRY_RUN([
3115+
#include <unistd.h>
3116+
#include <fcntl.h>
3117+
#include <stdio.h>
3118+
#include <semaphore.h>
3119+
#include <sys/stat.h>
3120+
3121+
int main(void){
3122+
sem_t *a = sem_open("/autoconf", O_CREAT, S_IRUSR|S_IWUSR, 0);
3123+
int count;
3124+
int res;
3125+
if(a==SEM_FAILED){
3126+
perror("sem_open");
3127+
return 1;
3128+
3129+
}
3130+
res = sem_getvalue(a, &count);
3131+
sem_close(a);
3132+
return res==-1 ? 1 : 0;
3133+
}
3134+
]
3135+
,AC_MSG_RESULT(no),
3136+
AC_MSG_RESULT(yes)
3137+
AC_DEFINE(HAVE_BROKEN_SEM_GETVALUE, 1, define to 1 if your sem_getvalue is broken.)
3138+
)
31113139

31123140
# On FreeBSD 6.2, it appears that tanh(-0.) returns 0. instead of
31133141
# -0. on some architectures.

0 commit comments

Comments
 (0)