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
Leak of locks from multiprocessing.Process #87311
Comments
The following C code leaks 7 locks allocated with PyThread_allocate_lock: #include <Python.h>
int main()
{
Py_Initialize();
PyObject* multiprocessing = PyImport_ImportModule("multiprocessing");
PyObject* Process = PyObject_GetAttrString(multiprocessing, "Process");
PyObject* args = PyTuple_New(0);
PyObject* kw = PyDict_New();
PyDict_SetItemString(kw, "target", Process);
PyObject* p = PyObject_Call(Process, args, kw);
PyObject* start = PyObject_GetAttrString(p, "start");
PyObject* join = PyObject_GetAttrString(p, "join");
PyObject_CallNoArgs(start);
PyObject_CallNoArgs(join);
Py_DECREF(join);
Py_DECREF(start);
Py_DECREF(p);
Py_DECREF(kw);
Py_DECREF(args);
Py_DECREF(Process);
Py_DECREF(multiprocessing);
Py_Finalize();
} The following locks are leaked:
In the attachment is valgrind's output. |
Slightly simpler C example: #include <Python.h>
int main()
{
Py_Initialize();
PyObject* multiprocessing = PyImport_ImportModule("multiprocessing");
PyObject* Process = PyObject_GetAttrString(multiprocessing, "Process");
PyObject* p = PyObject_CallNoArgs(Process);
PyObject* start = PyObject_GetAttrString(p, "start");
PyObject* join = PyObject_GetAttrString(p, "join");
Py_DECREF(PyObject_CallNoArgs(start));
Py_DECREF(PyObject_CallNoArgs(join));
Py_DECREF(join);
Py_DECREF(start);
Py_DECREF(p);
Py_DECREF(Process);
Py_DECREF(multiprocessing);
Py_Finalize();
} |
The pid = os.fork()
if pid == 0: os._exit() Translated to C: int main() {
Py_Initialize();
PyOS_BeforeFork();
pid_t pid = fork();
if (pid == 0) {
PyOS_AfterFork_Child(); // Reinitializes stuff.
_exit(0); // Child process exits without cleanup.
}
PyOS_AfterFork_Parent();
Py_Finalize();
} The call to My attempts at cleaning this up resulted in even more problems. |
Hi, Boris. Thanks for your report. We may receive the wrong alarm sometimes when we use valgrind.
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: