This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Can segfault Python with itertools.chain.from_iterable
Type: crash Stage: resolved
Components: Extension Modules Versions: Python 3.6, Python 3.4, Python 3.5, Python 2.7
Status: closed Resolution: duplicate
Dependencies: Superseder: deeply nested itertools objects segfault
View: 14010
Assigned To: rhettinger Nosy List: Evan Hubinger, josh.r, rhettinger, serhiy.storchaka
Priority: normal Keywords:

Created on 2015-10-17 02:11 by Evan Hubinger, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg253112 - (view) Author: Evan Hubinger (Evan Hubinger) * Date: 2015-10-17 02:11
The code

import itertools
it = itertools.chain.from_iterable((f() for f in [lambda: it]))

definitely segfaults on Python 2.6, 2.7, 3.3, and 3.4, and probably segfaults on other versions as well. The code is clearly incorrect in that the lambda references the variable being defined, but it seems like it should raise an error instead of segfaulting.
msg253119 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2015-10-17 04:46
Also crashes in 3.5.0 (on Windows 7, with 64 bit build).
msg253120 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-10-17 05:11
This is a duplicate of Issue #14010.  This issue runs deep and isn't itertools specific.  Running infinite chains of iterators pushes a number of CPython internals past their limits.  The best solutions are hard (monitoring the C-stack or fixing every possible fault at the fracture point).  The simplest solution (adding recursion count tracking to every possible iteration)is very heavy-handed and would slow-down all of Python in order to spare exotic cases that don't seem to arise in practice.
msg253123 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-10-17 06:57
Actually this issue an exact duplicate of issue22911 that is a duplicate of issue14010.
Date User Action Args
2022-04-11 14:58:22adminsetgithub: 69615
2015-10-17 17:17:52zach.waresetstage: resolved
2015-10-17 06:58:28serhiy.storchakasetsuperseder: deeply nested itertools objects segfault
2015-10-17 06:57:29serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg253123
2015-10-17 05:11:29rhettingersetstatus: open -> closed
resolution: duplicate
messages: + msg253120
2015-10-17 04:46:43josh.rsetnosy: + josh.r
messages: + msg253119
2015-10-17 03:00:15zach.waresetassignee: rhettinger

nosy: + rhettinger
components: + Extension Modules
versions: + Python 3.5, Python 3.6, - Python 3.2, Python 3.3
2015-10-17 02:11:53Evan Hubingercreate