Feature
As itertools.tee generates n independent iterators from a single iterable object, each IterNext of itertools.tee object will access the shallow-copy of PyItertoolsTeeData .
We need to prevent re-entering get_item method of PyItertoolsTeeData during iteration for keeping PyItertoolsTeeData thread-safety.
CPython use running variable whether the current entering is re-entering or first-entering like below code
// In a middle of get_item method of PyItertoolsTeeData
if (tdo->running) {
PyErr_SetString(PyExc_RuntimeError,
"cannot re-enter the tee iterator");
return NULL;
}
tdo->running = 1;
value = PyIter_Next(tdo->it);
tdo->running = 0;
Python Documentation
Relevant Test Case
test_itertools.py test_tee_reenter
Feature
As
itertools.teegeneratesnindependent iterators from a single iterable object, eachIterNextofitertools.teeobject will access theshallow-copyofPyItertoolsTeeData.We need to prevent re-entering
get_itemmethod ofPyItertoolsTeeDataduring iteration for keepingPyItertoolsTeeDatathread-safety.CPython use
runningvariable whether the current entering is re-entering or first-entering like below codePython Documentation
Relevant Test Case
test_itertools.pytest_tee_reenter