[issue43145] Leak of locks in a subprocess

2021-02-06 Thread Yannick Jadoul


Change by Yannick Jadoul :


--
nosy: +YannickJadoul

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43145] Leak of locks in a subprocess

2021-02-06 Thread Boris Staletic


Boris Staletic  added the comment:

Slightly simpler C example:

#include 

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();
}

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43145] Leak of locks in a subprocess

2021-02-06 Thread Boris Staletic


New submission from Boris Staletic :

The following C code leaks 7 locks allocated with PyThread_allocate_lock:

#include 

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:

1. 
https://github.com/python/cpython/blob/196d4deaf4810a0bba75ba537dd40f2d71a5a634/Python/pystate.c#L78
2. 
https://github.com/python/cpython/blob/196d4deaf4810a0bba75ba537dd40f2d71a5a634/Python/pystate.c#L84
3. 
https://github.com/python/cpython/blob/196d4deaf4810a0bba75ba537dd40f2d71a5a634/Python/pystate.c#L90
4. https://github.com/python/cpython/blob/master/Python/ceval.c#L810
5. https://github.com/python/cpython/blob/master/Python/import.c#L126
6. and 7. 
https://github.com/python/cpython/blob/master/Modules/_threadmodule.c#L597

In the attachment is valgrind's output.

--
components: C API
files: log
messages: 386558
nosy: bstaletic
priority: normal
severity: normal
status: open
title: Leak of locks in a subprocess
type: resource usage
versions: Python 3.10, Python 3.9
Added file: https://bugs.python.org/file49793/log

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com