annotate Modules/_multiprocessing/multiprocessing.c @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents c116b658aede
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
1 /*
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
2 * Extension module used by multiprocessing package
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
3 *
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
4 * multiprocessing.c
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
5 *
76663
25cc0c8fd4e2 Mark multiprocessing files with "Licensed to PSF under a Contributor Agreement"
Richard Oudkerk <shibturn@gmail.com>
parents: 76405
diff changeset
6 * Copyright (c) 2006-2008, R Oudkerk
25cc0c8fd4e2 Mark multiprocessing files with "Licensed to PSF under a Contributor Agreement"
Richard Oudkerk <shibturn@gmail.com>
parents: 76405
diff changeset
7 * Licensed to PSF under a Contributor Agreement.
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
8 */
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
9
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
10 #include "multiprocessing.h"
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
11
52902
d3887dfe661f Merged revisions 70908,70939,71009,71022,71036 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 47698
diff changeset
12
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
13 /*
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
14 * Function which raises exceptions based on error codes
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
15 */
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
16
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
17 PyObject *
79582
fc011f1ef59e Get rid of circular import and eliminate unprefixed exported symbols
Richard Oudkerk <shibturn@gmail.com>
parents: 77172
diff changeset
18 _PyMp_SetError(PyObject *Type, int num)
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
19 {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
20 switch (num) {
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
21 #ifdef MS_WINDOWS
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
22 case MP_STANDARD_ERROR:
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
23 if (Type == NULL)
80944
bb94f6222fef Issue #16719: Get rid of WindowsError. Use OSError instead
Andrew Svetlov <andrew.svetlov@gmail.com>
parents: 79582
diff changeset
24 Type = PyExc_OSError;
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
25 PyErr_SetExcFromWindowsErr(Type, 0);
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
26 break;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
27 case MP_SOCKET_ERROR:
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
28 if (Type == NULL)
80944
bb94f6222fef Issue #16719: Get rid of WindowsError. Use OSError instead
Andrew Svetlov <andrew.svetlov@gmail.com>
parents: 79582
diff changeset
29 Type = PyExc_OSError;
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
30 PyErr_SetExcFromWindowsErr(Type, WSAGetLastError());
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
31 break;
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
32 #else /* !MS_WINDOWS */
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
33 case MP_STANDARD_ERROR:
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
34 case MP_SOCKET_ERROR:
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
35 if (Type == NULL)
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
36 Type = PyExc_OSError;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
37 PyErr_SetFromErrno(Type);
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
38 break;
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
39 #endif /* !MS_WINDOWS */
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
40 case MP_MEMORY_ERROR:
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
41 PyErr_NoMemory();
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
42 break;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
43 case MP_EXCEPTION_HAS_BEEN_SET:
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
44 break;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
45 default:
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
46 PyErr_Format(PyExc_RuntimeError,
83779
36be00c51a66 - Fix typos in the multiprocessing module.
doko@ubuntu.com
parents: 77172
diff changeset
47 "unknown error number %d", num);
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
48 }
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
49 return NULL;
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
50 }
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
51
76405
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
52 #ifdef MS_WINDOWS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
53 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
54 multiprocessing_closesocket(PyObject *self, PyObject *args)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
55 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
56 HANDLE handle;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
57 int ret;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
58
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
59 if (!PyArg_ParseTuple(args, F_HANDLE ":closesocket" , &handle))
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
60 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
61
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
62 Py_BEGIN_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
63 ret = closesocket((SOCKET) handle);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
64 Py_END_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
65
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
66 if (ret)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
67 return PyErr_SetExcFromWindowsErr(PyExc_IOError, WSAGetLastError());
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
68 Py_RETURN_NONE;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
69 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
70
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
71 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
72 multiprocessing_recv(PyObject *self, PyObject *args)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
73 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
74 HANDLE handle;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
75 int size, nread;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
76 PyObject *buf;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
77
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
78 if (!PyArg_ParseTuple(args, F_HANDLE "i:recv" , &handle, &size))
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
79 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
80
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
81 buf = PyBytes_FromStringAndSize(NULL, size);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
82 if (!buf)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
83 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
84
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
85 Py_BEGIN_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
86 nread = recv((SOCKET) handle, PyBytes_AS_STRING(buf), size, 0);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
87 Py_END_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
88
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
89 if (nread < 0) {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
90 Py_DECREF(buf);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
91 return PyErr_SetExcFromWindowsErr(PyExc_IOError, WSAGetLastError());
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
92 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
93 _PyBytes_Resize(&buf, nread);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
94 return buf;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
95 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
96
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
97 static PyObject *
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
98 multiprocessing_send(PyObject *self, PyObject *args)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
99 {
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
100 HANDLE handle;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
101 Py_buffer buf;
85591
c116b658aede Fix conversion from Py_ssize_t to int.
Richard Oudkerk <shibturn@gmail.com>
parents: 85169
diff changeset
102 int ret, length;
76405
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
103
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
104 if (!PyArg_ParseTuple(args, F_HANDLE "y*:send" , &handle, &buf))
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
105 return NULL;
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
106
85591
c116b658aede Fix conversion from Py_ssize_t to int.
Richard Oudkerk <shibturn@gmail.com>
parents: 85169
diff changeset
107 length = (int)Py_MIN(buf.len, INT_MAX);
c116b658aede Fix conversion from Py_ssize_t to int.
Richard Oudkerk <shibturn@gmail.com>
parents: 85169
diff changeset
108
76405
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
109 Py_BEGIN_ALLOW_THREADS
85591
c116b658aede Fix conversion from Py_ssize_t to int.
Richard Oudkerk <shibturn@gmail.com>
parents: 85169
diff changeset
110 ret = send((SOCKET) handle, buf.buf, length, 0);
76405
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
111 Py_END_ALLOW_THREADS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
112
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
113 PyBuffer_Release(&buf);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
114 if (ret < 0)
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
115 return PyErr_SetExcFromWindowsErr(PyExc_IOError, WSAGetLastError());
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
116 return PyLong_FromLong(ret);
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
117 }
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
118
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
119 #endif
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
120
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
121 /*
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
122 * Function table
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
123 */
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
124
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
125 static PyMethodDef module_methods[] = {
76405
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
126 #ifdef MS_WINDOWS
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
127 {"closesocket", multiprocessing_closesocket, METH_VARARGS, ""},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
128 {"recv", multiprocessing_recv, METH_VARARGS, ""},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
129 {"send", multiprocessing_send, METH_VARARGS, ""},
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
130 #endif
85169
3b82e0d83bf9 Issue #8713: Support alternative start methods in multiprocessing on Unix.
Richard Oudkerk <shibturn@gmail.com>
parents: 83780
diff changeset
131 {"sem_unlink", _PyMp_sem_unlink, METH_VARARGS, ""},
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
132 {NULL}
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
133 };
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
134
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
135
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
136 /*
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
137 * Initialize
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
138 */
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
139
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
140 static struct PyModuleDef multiprocessing_module = {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
141 PyModuleDef_HEAD_INIT,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
142 "_multiprocessing",
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
143 NULL,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
144 -1,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
145 module_methods,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
146 NULL,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
147 NULL,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
148 NULL,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
149 NULL
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
150 };
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
151
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
152
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
153 PyMODINIT_FUNC
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
154 PyInit__multiprocessing(void)
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
155 {
74365
42d95944662d Fix compilation warning on Windows
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 73963
diff changeset
156 PyObject *module, *temp, *value = NULL;
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
157
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
158 /* Initialize module */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
159 module = PyModule_Create(&multiprocessing_module);
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
160 if (!module)
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
161 return NULL;
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
162
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
163 #if defined(MS_WINDOWS) || \
57491
3d77d7c16c90 Merged revisions 76566 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 52902
diff changeset
164 (defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED))
79582
fc011f1ef59e Get rid of circular import and eliminate unprefixed exported symbols
Richard Oudkerk <shibturn@gmail.com>
parents: 77172
diff changeset
165 /* Add _PyMp_SemLock type to module */
fc011f1ef59e Get rid of circular import and eliminate unprefixed exported symbols
Richard Oudkerk <shibturn@gmail.com>
parents: 77172
diff changeset
166 if (PyType_Ready(&_PyMp_SemLockType) < 0)
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
167 return NULL;
79582
fc011f1ef59e Get rid of circular import and eliminate unprefixed exported symbols
Richard Oudkerk <shibturn@gmail.com>
parents: 77172
diff changeset
168 Py_INCREF(&_PyMp_SemLockType);
65426
eabc5c53f134 Fix multiprocessing Semaphore's on netbsd5. SEM_VALUE_MAX is defined
Gregory P. Smith <greg@mad-scientist.com>
parents: 61466
diff changeset
169 {
eabc5c53f134 Fix multiprocessing Semaphore's on netbsd5. SEM_VALUE_MAX is defined
Gregory P. Smith <greg@mad-scientist.com>
parents: 61466
diff changeset
170 PyObject *py_sem_value_max;
eabc5c53f134 Fix multiprocessing Semaphore's on netbsd5. SEM_VALUE_MAX is defined
Gregory P. Smith <greg@mad-scientist.com>
parents: 61466
diff changeset
171 /* Some systems define SEM_VALUE_MAX as an unsigned value that
eabc5c53f134 Fix multiprocessing Semaphore's on netbsd5. SEM_VALUE_MAX is defined
Gregory P. Smith <greg@mad-scientist.com>
parents: 61466
diff changeset
172 * causes it to be negative when used as an int (NetBSD). */
eabc5c53f134 Fix multiprocessing Semaphore's on netbsd5. SEM_VALUE_MAX is defined
Gregory P. Smith <greg@mad-scientist.com>
parents: 61466
diff changeset
173 if ((int)(SEM_VALUE_MAX) < 0)
eabc5c53f134 Fix multiprocessing Semaphore's on netbsd5. SEM_VALUE_MAX is defined
Gregory P. Smith <greg@mad-scientist.com>
parents: 61466
diff changeset
174 py_sem_value_max = PyLong_FromLong(INT_MAX);
eabc5c53f134 Fix multiprocessing Semaphore's on netbsd5. SEM_VALUE_MAX is defined
Gregory P. Smith <greg@mad-scientist.com>
parents: 61466
diff changeset
175 else
eabc5c53f134 Fix multiprocessing Semaphore's on netbsd5. SEM_VALUE_MAX is defined
Gregory P. Smith <greg@mad-scientist.com>
parents: 61466
diff changeset
176 py_sem_value_max = PyLong_FromLong(SEM_VALUE_MAX);
eabc5c53f134 Fix multiprocessing Semaphore's on netbsd5. SEM_VALUE_MAX is defined
Gregory P. Smith <greg@mad-scientist.com>
parents: 61466
diff changeset
177 if (py_sem_value_max == NULL)
eabc5c53f134 Fix multiprocessing Semaphore's on netbsd5. SEM_VALUE_MAX is defined
Gregory P. Smith <greg@mad-scientist.com>
parents: 61466
diff changeset
178 return NULL;
79582
fc011f1ef59e Get rid of circular import and eliminate unprefixed exported symbols
Richard Oudkerk <shibturn@gmail.com>
parents: 77172
diff changeset
179 PyDict_SetItemString(_PyMp_SemLockType.tp_dict, "SEM_VALUE_MAX",
65426
eabc5c53f134 Fix multiprocessing Semaphore's on netbsd5. SEM_VALUE_MAX is defined
Gregory P. Smith <greg@mad-scientist.com>
parents: 61466
diff changeset
180 py_sem_value_max);
eabc5c53f134 Fix multiprocessing Semaphore's on netbsd5. SEM_VALUE_MAX is defined
Gregory P. Smith <greg@mad-scientist.com>
parents: 61466
diff changeset
181 }
79582
fc011f1ef59e Get rid of circular import and eliminate unprefixed exported symbols
Richard Oudkerk <shibturn@gmail.com>
parents: 77172
diff changeset
182 PyModule_AddObject(module, "SemLock", (PyObject*)&_PyMp_SemLockType);
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
183 #endif
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
184
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
185 /* Add configuration macros */
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
186 temp = PyDict_New();
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
187 if (!temp)
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
188 return NULL;
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
189
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
190 #define ADD_FLAG(name) \
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
191 value = Py_BuildValue("i", name); \
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
192 if (value == NULL) { Py_DECREF(temp); return NULL; } \
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
193 if (PyDict_SetItemString(temp, #name, value) < 0) { \
76405
f3a27d11101a Issue #11750: The Windows API functions scattered in the _subprocess and
Antoine Pitrou <solipsis@pitrou.net>
parents: 74365
diff changeset
194 Py_DECREF(temp); Py_DECREF(value); return NULL; } \
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
195 Py_DECREF(value)
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
196
57491
3d77d7c16c90 Merged revisions 76566 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 52902
diff changeset
197 #if defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED)
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
198 ADD_FLAG(HAVE_SEM_OPEN);
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
199 #endif
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
200 #ifdef HAVE_SEM_TIMEDWAIT
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
201 ADD_FLAG(HAVE_SEM_TIMEDWAIT);
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
202 #endif
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
203 #ifdef HAVE_BROKEN_SEM_GETVALUE
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
204 ADD_FLAG(HAVE_BROKEN_SEM_GETVALUE);
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
205 #endif
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
206 #ifdef HAVE_BROKEN_SEM_UNLINK
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
207 ADD_FLAG(HAVE_BROKEN_SEM_UNLINK);
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
208 #endif
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
209
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
210 if (PyModule_AddObject(module, "flags", temp) < 0)
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
211 return NULL;
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
212
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 57491
diff changeset
213 return module;
47698
6d1dc761ab4e fix multiprocessing line endings in py3k
Benjamin Peterson <benjamin@python.org>
parents: 47685
diff changeset
214 }