[Python-ideas] Add lookahead iterator (peeker) to itertools

Masklinn masklinn at masklinn.net
Tue Feb 26 11:06:45 CET 2013


On 2013-02-26, at 10:44 , Serhiy Storchaka wrote:

> On 26.02.13 11:23, Masklinn wrote:
>> On 2013-02-26, at 10:19 , Serhiy Storchaka wrote:
>>> My note is that if you create tee every iteration, this will lead to an linear increase in memory consumption and degradation of speed.
>> 
>> I believe I also saw situations where I blew through the recursion limit
>> by stacking too many tees, but I can't reproduce it right now.
> 
> http://bugs.python.org/issue13454 ?

No, it was a recursion limit, I was trying to use iterators in a
situation where I needed multiline lookaheads and skipping so I stacked
at least 1 tee + 1 islice per item and it blew up at one point. I can't
reproduce it anymore and I can't find the original code (replacing it
with straight lists ended up being simpler)

Although I can trivially get a segfault with islice:

    from itertools import islice, count

    it = count()
    while True:
        it = islice(it, 0)

Run this, C-c at some point, every CPython version on my machine
segfaults (pypy does not)


More information about the Python-ideas mailing list