Skip to content

Commit e77b639

Browse files
committed
Make accumulate thread-safe
1 parent 009c8c0 commit e77b639

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Modules/itertoolsmodule.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3063,7 +3063,7 @@ accumulate_traverse(PyObject *op, visitproc visit, void *arg)
30633063
}
30643064

30653065
static PyObject *
3066-
accumulate_next(PyObject *op)
3066+
accumulate_next_lock_held(PyObject *op)
30673067
{
30683068
accumulateobject *lz = accumulateobject_CAST(op);
30693069
PyObject *val, *newtotal;
@@ -3095,6 +3095,16 @@ accumulate_next(PyObject *op)
30953095
return newtotal;
30963096
}
30973097

3098+
static PyObject *
3099+
accumulate_next(PyObject *op)
3100+
{
3101+
PyObject *result;
3102+
Py_BEGIN_CRITICAL_SECTION(op);
3103+
result = accumulate_next_lock_held(op);
3104+
Py_END_CRITICAL_SECTION()
3105+
return result;
3106+
}
3107+
30983108
static PyType_Slot accumulate_slots[] = {
30993109
{Py_tp_dealloc, accumulate_dealloc},
31003110
{Py_tp_getattro, PyObject_GenericGetAttr},

0 commit comments

Comments
 (0)