Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #22261 > unrolled thread
| Started by | Dave Angel <d@davea.name> |
|---|---|
| First post | 2012-03-27 22:38 -0400 |
| Last post | 2012-03-27 22:38 -0400 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: python segfault Dave Angel <d@davea.name> - 2012-03-27 22:38 -0400
| From | Dave Angel <d@davea.name> |
|---|---|
| Date | 2012-03-27 22:38 -0400 |
| Subject | Re: python segfault |
| Message-ID | <mailman.1059.1332902301.3037.python-list@python.org> |
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. -- DaveA
Back to top | Article view | comp.lang.python
csiph-web