Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.196 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.62; '*S*': 0.01; ';-)': 0.03; 'fault': 0.07; 'function,': 0.09; 'python': 0.11; 'subject:python': 0.12; 'cc:addr:python-list': 0.15; '2.7.2': 0.16; 'ubuntu,': 0.16; 'wien,': 0.16; 'zeros': 0.16; 'wrote:': 0.21; 'exception': 0.22; 'header:In-Reply-To:1': 0.22; 'header:User-Agent:1': 0.23; '(or': 0.24; 'cc:no real name:2**0': 0.26; 'quite': 0.26; 'cc:addr:python.org': 0.27; 'pm,': 0.28; 'equivalent.': 0.29; 'question': 0.30; 'raise': 0.30; 'cc:2**0': 0.31; 'asked': 0.31; 'hi,': 0.33; 'two': 0.35; 'there': 0.35; 'beginning': 0.35; 'why': 0.36; 'but': 0.36; 'charset:us-ascii': 0.36; 'thank': 0.37; 'subject:': 0.38; 'michael': 0.38; 'clear': 0.39; "can't": 0.39; 'large': 0.40; 'steps': 0.61; 'course': 0.61; 'content- disposition:inline': 0.62; 'skip:n 10': 0.62; 'skip:+ 10': 0.63; 'real': 0.63; 'most': 0.63; 'remove': 0.65; 'quick': 0.66; 'materials': 0.70; 'bound': 0.72; 'limit': 0.73; 'size.': 0.79; 'default': 0.81; 'obvious': 0.81; '(quick': 0.84; 'davea': 0.84; 'recursion': 0.84; 'true:': 0.84; 'voice:': 0.84; 'angel': 0.91; 'explained': 0.91 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=univie.ac.at; s=rev2; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=wo5ZXXcazes10Na2DJWSZgvcEFi4nc23oTFvS+KchqM=; b=XujR1bJmMNN2E+UQU3nH8YfObkNh9R6PITe+0haEi8r2nMp+1WD/dNb4piYEVd/X6ygKc2Q2zRc7hIZnFlt3QJrVdvGtn8GuiQ0S1/CwOdO6JVgOK/Z7SQ9gClDE4FG36uPcXhCcaeliA/kpglUQzvmxUMGCkPhvWrTvciIG0Zc=; Date: Wed, 28 Mar 2012 08:16:50 +0200 From: Michael Poeltl To: Dave Angel Subject: Re: python segfault References: <20120327222757.GA22125@terra.cms.at> <4F727993.3070801@davea.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4F727993.3070801@davea.name> User-Agent: Mutt/1.5.21 (2010-09-15) X-Univie-Virus-Scan: scanned by ClamAV on jarvis.univie.ac.at Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 68 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1332915413 news.xs4all.nl 6885 [2001:888:2000:d::a6]:40222 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22262 hi, * Dave Angel [2012-03-28 04:38]: > On 03/27/2012 06:27 PM, Michael Poeltl wrote: > >hi, > > > >can anybody tell why this 'little stupid *thing* of code' let's python-3.2.2, 2.6.X or python 2.7.2 segfault? > > > >>>def get_steps2(pos=0, steps=0): > >... if steps == 0: > >... pos = random.randint(-1,1) > >... if pos == 0: > >... return steps > >... steps += 2 > >... pos += random.randint(-1,1) > >... return get_steps2(pos,steps) > >... > > > >0 > >2 > >8 > >0 > >Segmentation fault > >?> > > > >funny, isn't it? > >I was able to reproduce this segfault on various machines (32bit 64bit), ubuntu, slackware, debian > >python.X segfaults on all of them > > > >thx > >Michael > > Others have explained why you can't just raise the recursion limit > to arbitrarily large values, and why there's no particular bound on > the possible recursion size. But the real question is why you don't > do the completely trivial conversion to a non-recursive equivalent. > > All you need do is add a while True: to the beginning of the > function, and remove the return statement. yeah - of course 'while True' was the first, most obvious best way... ;-) but I was asked if there was a way without 'while True' and so I started the 'recursive function' and quick quick; RuntimeError-Exception -> not thinking much -> just adding two zeros to the default limit (quick and dirty) -> segfault ==> subject: python segfault ;-) and that was my first time that I received a segfault and not an Exception NOW it's quite clear ;-) thank you! Michael > > > > -- > > DaveA > -- Michael Poeltl Computational Materials Physics voice: +43-1-4277-51409 Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at ------------------------------------------------------------------------------- ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12 -------------------------------------------------------------------------------