Skip to content

Commit c528ba4

Browse files
serhiy-storchakalisroach
authored andcommitted
Revert "Raise a RuntimeError when tee iterator is consumed from different threads (pythonGH-15567)" (pythonGH-15736)
This reverts commit fa220ec.
1 parent a1999b4 commit c528ba4

File tree

3 files changed

+1
-12
lines changed

3 files changed

+1
-12
lines changed

Doc/library/itertools.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,7 @@ loops that truncate the stream.
643643

644644
Once :func:`tee` has made a split, the original *iterable* should not be
645645
used anywhere else; otherwise, the *iterable* could get advanced without
646-
the tee objects being informed. the :func:`tee` iterator can not be consumed
647-
from different threads, even if an underlying iterator is thread-safe.
646+
the tee objects being informed.
648647

649648
This itertool may require significant auxiliary storage (depending on how
650649
much temporary data needs to be stored). In general, if one iterator uses

Misc/NEWS.d/next/Library/2019-08-29-10-26-57.bpo-34410.ttCIpm.rst

Lines changed: 0 additions & 2 deletions
This file was deleted.

Modules/itertoolsmodule.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,6 @@ typedef struct {
452452
teedataobject *dataobj;
453453
int index; /* 0 <= index <= LINKCELLS */
454454
PyObject *weakreflist;
455-
unsigned long thread_id;
456455
} teeobject;
457456

458457
static PyTypeObject teedataobject_type;
@@ -681,11 +680,6 @@ tee_next(teeobject *to)
681680
{
682681
PyObject *value, *link;
683682

684-
if (to->thread_id != PyThread_get_thread_ident()) {
685-
PyErr_SetString(PyExc_RuntimeError,
686-
"tee() iterator can not be consumed from different threads.");
687-
return NULL;
688-
}
689683
if (to->index >= LINKCELLS) {
690684
link = teedataobject_jumplink(to->dataobj);
691685
if (link == NULL)
@@ -719,7 +713,6 @@ tee_copy(teeobject *to, PyObject *Py_UNUSED(ignored))
719713
newto->dataobj = to->dataobj;
720714
newto->index = to->index;
721715
newto->weakreflist = NULL;
722-
newto->thread_id = to->thread_id;
723716
PyObject_GC_Track(newto);
724717
return (PyObject *)newto;
725718
}
@@ -752,7 +745,6 @@ tee_fromiterable(PyObject *iterable)
752745

753746
to->index = 0;
754747
to->weakreflist = NULL;
755-
to->thread_id = PyThread_get_thread_ident();
756748
PyObject_GC_Track(to);
757749
done:
758750
Py_XDECREF(it);

0 commit comments

Comments
 (0)