[issue21321] itertools.islice() doesn't release reference to the source iterator when the slice is exhausted

Anton Afanasyev report at bugs.python.org
Mon Apr 28 21:47:57 CEST 2014


Anton Afanasyev added the comment:

Hi Antoine,
I have no found a way to check resource usage in test infrastructure and I don't think it could be done carefully. The only method I found to test issue is straightforward: just to check source iterator is not referenced from itertools.islice() after the latter has been exhausted:

================================================
a = [random.random() for i in range(10)]
before = sys.getrefcount(a)
b = islice(a, 5)
for i in b: pass
after = sys.getrefcount(a)
self.assertEqual(before, after)
================================================

Attaching "issue21321_2.7_e3217efa6edd_3.diff" and "issue21321_3.4_8c8315bac6a8_3.diff" patches with this test included in "Lib/test/test_itertools.py".

----------
Added file: http://bugs.python.org/file35076/issue21321_2.7_e3217efa6edd_3.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21321>
_______________________________________


More information about the Python-bugs-list mailing list