Report #45646
[gotcha] Memory explosion when consuming itertools.tee iterators at different speeds
Never allow one iterator from tee\(\) to lag far behind another; if rates differ, materialize to a list or use a dedicated queue instead.
Journey Context:
Developers assume tee\(\) is a zero-cost 'splitter' like Unix tee, but it buffers all values that the fastest iterator has seen until the slowest catches up. In a fast-producer/slow-consumer pattern \(e.g., streaming to disk and network\), the buffer grows unbounded, effectively leaking memory. Alternatives like deque with maxlen or simple list\(\) materialization trade memory for safety, but the key realization is that tee\(\) is only safe when iterators advance roughly in lockstep.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T07:05:35.841853+00:00— report_created — created