Skip to content

Document itertools.tee's internal batching#154369

Closed
jstriebel wants to merge 1 commit into
python:mainfrom
jstriebel:docs-itertools-tee-memory-note
Closed

Document itertools.tee's internal batching#154369
jstriebel wants to merge 1 commit into
python:mainfrom
jstriebel:docs-itertools-tee-memory-note

Conversation

@jstriebel

Copy link
Copy Markdown

Add an impl-detail note to itertools.tee, explaining that CPython caches items in fixed-size batches of 57 items currently. This is relevant for iterators with memory-intensive items.

A small example showing the batching in action:

from itertools import tee

class LoudLifecycle:
    def __init__(self, i):
        self.i = i
        print(f"INIT {self.i}")

    def __del__(self):
        print(f"DEL {self.i}")

def my_iter():
    for i in range(100):
        yield LoudLifecycle(i)

a, b = tee(my_iter())

for _ in zip(a, b):
    pass

Add an impl-detail note to itertools.tee, explaining that CPython
caches items in fixed-size batches of 57 items currently. This is
relevant for iterators with memory-intensive items.
@jstriebel
jstriebel requested a review from rhettinger as a code owner July 21, 2026 14:43
@bedevere-app bedevere-app Bot added docs Documentation in the Doc dir skip news labels Jul 21, 2026
@python-cla-bot

python-cla-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33689974 | 📁 Comparing 9317c8f against main (bfd774d)

  🔍 Preview build  

1 file changed
± library/itertools.html

@picnixz

picnixz commented Jul 21, 2026

Copy link
Copy Markdown
Member

We don't document such internals as they are subject to changes. It also came up in #138765. See also #138765 (comment).

@picnixz picnixz closed this Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants