Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #22262

Re: python segfault

Date 2012-03-28 08:16 +0200
From Michael Poeltl <michael.poeltl@univie.ac.at>
Subject Re: python segfault
References <20120327222757.GA22125@terra.cms.at> <4F727993.3070801@davea.name>
Newsgroups comp.lang.python
Message-ID <mailman.1060.1332915413.3037.python-list@python.org> (permalink)

Show all headers | View raw


hi,

* Dave Angel <d@davea.name> [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)
> >...
> ><SNIP>
> >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
-------------------------------------------------------------------------------

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: python segfault Michael Poeltl <michael.poeltl@univie.ac.at> - 2012-03-28 08:16 +0200
  Re: python segfault Kiuhnm <kiuhnm03.4t.yahoo.it> - 2012-03-28 15:59 +0200

csiph-web