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.

classification
Title: Segfault caused by weird combination of imports and yield from
Type: crash Stage: resolved
Components: Interpreter Core, Windows Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: benjamin.peterson Nosy List: Arfrever, benjamin.peterson, brett.cannon, eric.snow, fhamand, ncoghlan, pconnell, pitrou, python-dev, r.david.murray, vinay.sajip
Priority: normal Keywords: patch

Created on 2013-04-08 22:49 by fhamand, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
segfault.zip fhamand, 2013-04-08 22:55 minimum case to reproduce
gen_fix.patch benjamin.peterson, 2013-04-09 04:15 review
Messages (6)
msg186354 - (view) Author: Frank Hamand (fhamand) Date: 2013-04-08 22:55
I've found a very strange bug in python 3.3

It's taken me around an hour just to narrow it down to a small case where it happens.

I cannot for the life of me figure out the exact cause. It seems to have something to do with "yield from".

I've attached a case which reproduces this. Run python3.3 test.py, it should segfault on linux, "stopped responding" on windows.

Tested with
OS: Linux Debian-60-squeeze-32-minimal 2.6.32-5-686-bigmem
PY: Python 3.3.1rc1 (default, Mar 30 2013, 21:44:39)

OS: Windows 7 64 bit
PY: Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32


NOTES: If you get rid of "import logging" in generators.py, it only crashes if there's no __pycache__
msg186355 - (view) Author: Frank Hamand (fhamand) Date: 2013-04-08 22:59
The file contents so people dont have to download the zip:

generators.py:
---------------------------
def subgen():
	yield

def other_gen(self):
	move = yield from subgen()

game.py:
---------------------------
class Game(object):
	def __init__(self):
		self.gen = self.first_gen()
		next(self.gen)
	def first_gen(self):
		while True:
			from generators import \
				other_gen
			yield from other_gen(self)


test.py:
---------------------------
from game import Game
Game()
msg186365 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-04-09 01:27
The crashing version has 'import logging' at the top of generators.py.  I did not experience a crash when it was absent even if there was no __pycache__.

It also doesn't crash if the import is moved out of the body of first_gen.

FAULTHANDLER doesn't fair too well on this one, no real surprise :)

Fatal Python error: Segmentation fault

Current thread 0xb75856c0:
zsh: segmentation fault  PYTHONFAULTHANDLER=true ../python test.py
msg186370 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2013-04-09 04:15
This is the patch. I'll have to think about whether there's a self-contained way to test this.
msg186530 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-04-10 21:01
New changeset 35cb75b9d653 by Benjamin Peterson in branch '3.3':
don't run frame if it has no stack (closes #17669)
http://hg.python.org/cpython/rev/35cb75b9d653

New changeset 0b2d4089180c by Benjamin Peterson in branch 'default':
merge 3.3 (#17669)
http://hg.python.org/cpython/rev/0b2d4089180c
msg193797 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-07-27 21:07
New changeset 516303f32bad by Benjamin Peterson in branch '3.3':
add a test for issue #17669 (closes #18565)
http://hg.python.org/cpython/rev/516303f32bad
History
Date User Action Args
2022-04-11 14:57:44adminsetgithub: 61869
2013-07-29 08:55:44pconnellsetnosy: + pconnell
2013-07-27 21:07:37python-devsetmessages: + msg193797
2013-04-10 21:01:45python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg186530

resolution: fixed
stage: resolved
2013-04-09 20:48:43Arfreversetnosy: + Arfrever
2013-04-09 04:15:54benjamin.petersonsetfiles: + gen_fix.patch
assignee: benjamin.peterson
messages: + msg186370

keywords: + patch
2013-04-09 01:27:24r.david.murraysetnosy: + r.david.murray, pitrou, eric.snow, vinay.sajip, brett.cannon

messages: + msg186365
versions: + Python 3.4
2013-04-08 23:24:34pitrousetnosy: + ncoghlan, benjamin.peterson
2013-04-08 22:59:10fhamandsetmessages: + msg186355
2013-04-08 22:55:26fhamandsetfiles: + segfault.zip

messages: + msg186354
title: Segfault caused by -> Segfault caused by weird combination of imports and yield from
2013-04-08 22:49:14fhamandcreate