Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-1635741: port multiprocessing to multiphase init #21378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Port :mod:`multiprocessing` to multi-phase initialization
95 changes: 54 additions & 41 deletions 95 Modules/_multiprocessing/multiprocessing.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,35 +139,12 @@ static PyMethodDef module_methods[] = {
* Initialize
*/

static struct PyModuleDef multiprocessing_module = {
PyModuleDef_HEAD_INIT,
"_multiprocessing",
NULL,
-1,
module_methods,
NULL,
NULL,
NULL,
NULL
};


PyMODINIT_FUNC
PyInit__multiprocessing(void)
static int
multiprocessing_exec(PyObject *module)
{
PyObject *module, *temp, *value = NULL;

/* Initialize module */
module = PyModule_Create(&multiprocessing_module);
if (!module)
return NULL;

#if defined(MS_WINDOWS) || \
(defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED))
koubaa marked this conversation as resolved.
Show resolved Hide resolved
/* Add _PyMp_SemLock type to module */
if (PyType_Ready(&_PyMp_SemLockType) < 0)
koubaa marked this conversation as resolved.
Show resolved Hide resolved
return NULL;
Py_INCREF(&_PyMp_SemLockType);

{
PyObject *py_sem_value_max;
/* Some systems define SEM_VALUE_MAX as an unsigned value that
Expand All @@ -179,25 +156,42 @@ PyInit__multiprocessing(void)
py_sem_value_max = PyLong_FromLong(INT_MAX);
else
py_sem_value_max = PyLong_FromLong(SEM_VALUE_MAX);
if (py_sem_value_max == NULL)
return NULL;

if (py_sem_value_max == NULL) {
Py_DECREF(py_sem_value_max);
return -1;
}
PyDict_SetItemString(_PyMp_SemLockType.tp_dict, "SEM_VALUE_MAX",
koubaa marked this conversation as resolved.
Show resolved Hide resolved
koubaa marked this conversation as resolved.
Show resolved Hide resolved
py_sem_value_max);
}
PyModule_AddObject(module, "SemLock", (PyObject*)&_PyMp_SemLockType);

/* Add _PyMp_SemLock type to module */
Py_INCREF(&_PyMp_SemLockType);
koubaa marked this conversation as resolved.
Show resolved Hide resolved
if (PyModule_AddType(module, &_PyMp_SemLockType) < 0) {
Py_DECREF(&_PyMp_SemLockType);
return -1;
}

#endif

/* Add configuration macros */
temp = PyDict_New();
if (!temp)
return NULL;
PyObject *flags = PyDict_New();
if (!flags) {
return -1;
koubaa marked this conversation as resolved.
Show resolved Hide resolved
}

#define ADD_FLAG(name) \
value = Py_BuildValue("i", name); \
if (value == NULL) { Py_DECREF(temp); return NULL; } \
if (PyDict_SetItemString(temp, #name, value) < 0) { \
Py_DECREF(temp); Py_DECREF(value); return NULL; } \
Py_DECREF(value)
#define ADD_FLAG(name) { \
koubaa marked this conversation as resolved.
Show resolved Hide resolved
PyObject *value = PyLong_FromLong(name); \
if (value == NULL) { \
Py_DECREF(flags); \
return -1; } \
} \
if (PyDict_SetItemString(flags, #name, value) < 0) { \
Py_DECREF(flags); \
Py_DECREF(value); \
return -1; } \
Py_DECREF(value) \
}

#if defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED)
ADD_FLAG(HAVE_SEM_OPEN);
Expand All @@ -212,8 +206,27 @@ PyInit__multiprocessing(void)
ADD_FLAG(HAVE_BROKEN_SEM_UNLINK);
#endif

if (PyModule_AddObject(module, "flags", temp) < 0)
return NULL;
if (PyModule_AddObject(module, "flags", flags) < 0) {
koubaa marked this conversation as resolved.
Show resolved Hide resolved
return -1;
}

return 0;
}

return module;
static PyModuleDef_Slot multiprocessing_slots[] = {
{Py_mod_exec, multiprocessing_exec},
{0, NULL}
};

static struct PyModuleDef multiprocessing_module = {
PyModuleDef_HEAD_INIT,
.m_name = "_multiprocessing",
.m_methods = module_methods,
.m_slots = multiprocessing_slots,
};

PyMODINIT_FUNC
PyInit__multiprocessing(void)
{
return PyModuleDef_Init(&multiprocessing_module);
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.