Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #90725
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!feeds.phibee-telecom.net!news.panservice.it!feed.xsnews.nl!border01.ams.xsnews.nl!feeder04.ams.xsnews.nl!abp001.ams.xsnews.nl!frontend-F10-08.ams.news.kpn.nl |
|---|---|
| From | Cecil Westerhof <Cecil@decebal.nl> |
| Newsgroups | comp.lang.python |
| Subject | Re: Minimising stack trace |
| Organization | Decebal Computing |
| References | <871tih66z5.fsf@Equus.decebal.nl> <2c2b0f1d-ce16-41b4-a12d-1cface2bf154@googlegroups.com> |
| X-Face | "(y8cC@tg_12{">GF'UXTW]FHI2wMiZNrnf'1EFQ&O#$m:f#O7+7}kR<J%a^F2lh4[N~Yz4 nSp#c+aQo1b5=?HcNEkQ7QzF<])O3X4MDL/AYjys&*mt>,v+Pti8=Vi/Z"g^?b"E |
| X-Homepage | http://www.decebal.nl/ |
| Date | Sat, 16 May 2015 09:22:41 +0200 |
| Message-ID | <878ucpf0la.fsf@Equus.decebal.nl> (permalink) |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
| Cancel-Lock | sha1:j/q0N4Pk8drr5rcpER7WGh98uZQ= |
| MIME-Version | 1.0 |
| Content-Type | text/plain |
| Lines | 71 |
| NNTP-Posting-Host | 81.207.62.244 |
| X-Trace | 1431761359 news.kpn.nl 21210 81.207.62.244@kpn/81.207.62.244:37570 |
| Xref | csiph.com comp.lang.python:90725 |
Show key headers only | View raw
Op Friday 15 May 2015 21:04 CEST schreef Ned Batchelder:
> On Friday, May 15, 2015 at 2:50:12 PM UTC-4, Cecil Westerhof wrote:
>> While playing with recursion I get:
>> RuntimeError: maximum recursion depth exceeded in comparison
>>
>> But then I get a very long stack trace. Is there a way to make this
>> a lot shorter. Now I 'lose' interesting information because of the
>> length of the stack trace.
>
> There isn't a way to shorten the stack trace. If you are losing
> information at the top because of your terminal window, you can
> likely increase the number of lines it will keep for you.
Well, I am not really losing information, but it happens in a script
with some output. One of the things I output is information about how
deep I am going. If I then get a stack trace of a 1000 lines that is
not very helpful. Especially because except the first and last every
message is the same. What would be a lot more helpful would be
something like:
RuntimeError Traceback (most recent call last)
/home/cecil/Python/mathDecebal.py in <module>()
355 for i in range(start, end + 1):
356 factorial_iter = factorial_iterative(i)
--> 357 factorial_recur = factorial_recursive(i)
358 factorial_recur_old = factorial_recursive_old(i)
359 factorial_tail = factorial_tail_recursion(i)
/home/cecil/Python/mathDecebal.py in factorial_recursive(x, y, z)
51 if x < 2:
52 return y
---> 53 return y if z > x else factorial_recursive(x, z * y, z + 1)
54
55 def factorial_recursive_old(x, y = 1):
Last call repeated 153 times
/home/cecil/Python/mathDecebal.py in factorial_recursive(x, y, z)
48
49 def factorial_recursive(x, y = 1, z = 1):
---> 50 assert x >= 0
51 if x < 2:
52 return y
RuntimeError: maximum recursion depth exceeded in comparison
I would find that a lot clearer and I do not think you are losing
anything useful.
> Another option is to reduce the maximum stack depth, so that it
> is exceeded sooner, which produces shorter stack traces:
>
> import sys;
> sys.setrecursionlimit(50)
Well that would break my code. I just got the above problem with my
math functions. I had it tweaked for testing. But when running the
test in ipython3 it goes wrong. It looks like ipython3 has a smaller
stack, or puts more on the stack as ipython, python3 and python2.
Yes, that is correct. When running:
python3 mathDecebal.py
there is no problem, but when running:
ipython3 mathDecebal.py
I get a stack overflow.
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Minimising stack trace Cecil Westerhof <Cecil@decebal.nl> - 2015-05-15 20:17 +0200
Re: Minimising stack trace Ned Batchelder <ned@nedbatchelder.com> - 2015-05-15 12:04 -0700
Re: Minimising stack trace Skip Montanaro <skip.montanaro@gmail.com> - 2015-05-15 14:14 -0500
Re: Minimising stack trace Cecil Westerhof <Cecil@decebal.nl> - 2015-05-16 09:22 +0200
Re: Minimising stack trace Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-15 21:41 +0200
Re: Minimising stack trace Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-16 10:57 +1000
Re: Minimising stack trace Ned Batchelder <ned@nedbatchelder.com> - 2015-05-15 18:24 -0700
Re: Minimising stack trace Chris Angelico <rosuav@gmail.com> - 2015-05-16 11:33 +1000
Re: Minimising stack trace Ned Batchelder <ned@nedbatchelder.com> - 2015-05-15 18:37 -0700
Re: Minimising stack trace Rustom Mody <rustompmody@gmail.com> - 2015-05-15 19:51 -0700
Re: Minimising stack trace Rustom Mody <rustompmody@gmail.com> - 2015-05-15 19:59 -0700
Re: Minimising stack trace Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-05-16 04:49 +0100
Re: Minimising stack trace Cecil Westerhof <Cecil@decebal.nl> - 2015-05-16 15:49 +0200
csiph-web