Skip to content

Revert "bpo-34410: Raise a RuntimeError when tee iterator is consumed from different threads." #15736

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

Merged
merged 1 commit into from
Sep 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Doc/library/itertools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,7 @@ loops that truncate the stream.

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

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

This file was deleted.

8 changes: 0 additions & 8 deletions Modules/itertoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,6 @@ typedef struct {
teedataobject *dataobj;
int index; /* 0 <= index <= LINKCELLS */
PyObject *weakreflist;
unsigned long thread_id;
} teeobject;

static PyTypeObject teedataobject_type;
Expand Down Expand Up @@ -681,11 +680,6 @@ tee_next(teeobject *to)
{
PyObject *value, *link;

if (to->thread_id != PyThread_get_thread_ident()) {
PyErr_SetString(PyExc_RuntimeError,
"tee() iterator can not be consumed from different threads.");
return NULL;
}
if (to->index >= LINKCELLS) {
link = teedataobject_jumplink(to->dataobj);
if (link == NULL)
Expand Down Expand Up @@ -719,7 +713,6 @@ tee_copy(teeobject *to, PyObject *Py_UNUSED(ignored))
newto->dataobj = to->dataobj;
newto->index = to->index;
newto->weakreflist = NULL;
newto->thread_id = to->thread_id;
PyObject_GC_Track(newto);
return (PyObject *)newto;
}
Expand Down Expand Up @@ -752,7 +745,6 @@ tee_fromiterable(PyObject *iterable)

to->index = 0;
to->weakreflist = NULL;
to->thread_id = PyThread_get_thread_ident();
PyObject_GC_Track(to);
done:
Py_XDECREF(it);
Expand Down