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


Groups > comp.lang.python > #90686 > unrolled thread

Minimising stack trace

Started byCecil Westerhof <Cecil@decebal.nl>
First post2015-05-15 20:17 +0200
Last post2015-05-16 15:49 +0200
Articles 13 — 8 participants

Back to article view | Back to comp.lang.python


Contents

  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

#90686 — Minimising stack trace

FromCecil Westerhof <Cecil@decebal.nl>
Date2015-05-15 20:17 +0200
SubjectMinimising stack trace
Message-ID<871tih66z5.fsf@Equus.decebal.nl>
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.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [next] | [standalone]


#90688

FromNed Batchelder <ned@nedbatchelder.com>
Date2015-05-15 12:04 -0700
Message-ID<2c2b0f1d-ce16-41b4-a12d-1cface2bf154@googlegroups.com>
In reply to#90686
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.

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)


--Ned.

[toc] | [prev] | [next] | [standalone]


#90689

FromSkip Montanaro <skip.montanaro@gmail.com>
Date2015-05-15 14:14 -0500
Message-ID<mailman.46.1431717256.17265.python-list@python.org>
In reply to#90688
A third alternative is to take a look at asyncore.compact_traceback.
That will only help modestly in Cecil's example, but I found it
helpful.

Skip

On Fri, May 15, 2015 at 2:04 PM, Ned Batchelder <ned@nedbatchelder.com> wrote:
> 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.
>
> 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)
>
>
> --Ned.
> --
> https://mail.python.org/mailman/listinfo/python-list

[toc] | [prev] | [next] | [standalone]


#90725

FromCecil Westerhof <Cecil@decebal.nl>
Date2015-05-16 09:22 +0200
Message-ID<878ucpf0la.fsf@Equus.decebal.nl>
In reply to#90688
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

[toc] | [prev] | [next] | [standalone]


#90690

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2015-05-15 21:41 +0200
Message-ID<1585804.vCLx6kbzfH@PointedEars.de>
In reply to#90686
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.

<http://www.catb.org/~esr/faqs/smart-questions.html>

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#90703

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2015-05-16 10:57 +1000
Message-ID<55569607$0$13008$c3e8da3$5496439d@news.astraweb.com>
In reply to#90690
On Sat, 16 May 2015 05:41 am, Thomas 'PointedEars' Lahn wrote:

> 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.
> 
> <http://www.catb.org/~esr/faqs/smart-questions.html>

There ought to be a website that explains how to give smart answers.


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#90705

FromNed Batchelder <ned@nedbatchelder.com>
Date2015-05-15 18:24 -0700
Message-ID<9cbf3b8e-e830-46f5-a636-27c0d07f460a@googlegroups.com>
In reply to#90703
On Friday, May 15, 2015 at 8:57:53 PM UTC-4, Steven D'Aprano wrote:
> On Sat, 16 May 2015 05:41 am, Thomas 'PointedEars' Lahn wrote:
> 
> > 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.
> > 
> > <http://www.catb.org/~esr/faqs/smart-questions.html>
> 
> There ought to be a website that explains how to give smart answers.

Or one that explains how to be kind to those that don't know
the ropes yet.  Though pointing impatient experts at a
website probably won't get them to change any more than
brusquely pointing newbs at a website will.

--Ned.

[toc] | [prev] | [next] | [standalone]


#90707

FromChris Angelico <rosuav@gmail.com>
Date2015-05-16 11:33 +1000
Message-ID<mailman.55.1431739994.17265.python-list@python.org>
In reply to#90705
On Sat, May 16, 2015 at 11:24 AM, Ned Batchelder <ned@nedbatchelder.com> wrote:
> On Friday, May 15, 2015 at 8:57:53 PM UTC-4, Steven D'Aprano wrote:
>> On Sat, 16 May 2015 05:41 am, Thomas 'PointedEars' Lahn wrote:
>>
>> > 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.
>> >
>> > <http://www.catb.org/~esr/faqs/smart-questions.html>
>>
>> There ought to be a website that explains how to give smart answers.
>
> Or one that explains how to be kind to those that don't know
> the ropes yet.  Though pointing impatient experts at a
> website probably won't get them to change any more than
> brusquely pointing newbs at a website will.

You mean like this?

http://www.catb.org/~esr/faqs/smart-questions.html#idp64834912

(Not sure whether you knew and were hinting, or didn't know that
that's explicitly mentioned.)

ChrisA

[toc] | [prev] | [next] | [standalone]


#90708

FromNed Batchelder <ned@nedbatchelder.com>
Date2015-05-15 18:37 -0700
Message-ID<b644d3ca-58cc-4dd6-adaa-c9cc73ec39dd@googlegroups.com>
In reply to#90707
On Friday, May 15, 2015 at 9:33:54 PM UTC-4, Chris Angelico wrote:
> On Sat, May 16, 2015 at 11:24 AM, Ned Batchelder <ned@nedbatchelder.com> wrote:
> > On Friday, May 15, 2015 at 8:57:53 PM UTC-4, Steven D'Aprano wrote:
> >> On Sat, 16 May 2015 05:41 am, Thomas 'PointedEars' Lahn wrote:
> >>
> >> > 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.
> >> >
> >> > <http://www.catb.org/~esr/faqs/smart-questions.html>
> >>
> >> There ought to be a website that explains how to give smart answers.
> >
> > Or one that explains how to be kind to those that don't know
> > the ropes yet.  Though pointing impatient experts at a
> > website probably won't get them to change any more than
> > brusquely pointing newbs at a website will.
> 
> You mean like this?
> 
> http://www.catb.org/~esr/faqs/smart-questions.html#idp64834912
> 
> (Not sure whether you knew and were hinting, or didn't know that
> that's explicitly mentioned.)

I didn't realize that was in there. :) It's a good demonstration
that we can all improve in various ways.  Being right isn't the
highest ideal, there are other things to aspire to as well.

--Ned.

[toc] | [prev] | [next] | [standalone]


#90714

FromRustom Mody <rustompmody@gmail.com>
Date2015-05-15 19:51 -0700
Message-ID<5581b381-8c45-4aa1-b037-32aee59f4463@googlegroups.com>
In reply to#90705
On Saturday, May 16, 2015 at 6:54:23 AM UTC+5:30, Ned Batchelder wrote:
> On Friday, May 15, 2015 at 8:57:53 PM UTC-4, Steven D'Aprano wrote:
> > On Sat, 16 May 2015 05:41 am, Thomas 'PointedEars' Lahn wrote:
> > 
> > > 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.
> > > 
> > > <http://www.catb.org/~esr/faqs/smart-questions.html>
> > 
> > There ought to be a website that explains how to give smart answers.
> 
> Or one that explains how to be kind to those that don't know
> the ropes yet.  Though pointing impatient experts at a
> website probably won't get them to change any more than
> brusquely pointing newbs at a website will.

How about a 'answerer-quota' 😇 ?

« Once for every 20 useful answers you are allowed to vent on any subject of 
  your choice...

  - Stupid questions (and point to catb's smart questions)
  - Google groups
  - Top posting
  - Html mail

»

[toc] | [prev] | [next] | [standalone]


#90715

FromRustom Mody <rustompmody@gmail.com>
Date2015-05-15 19:59 -0700
Message-ID<51084a44-3ac1-4c9e-a83d-d75b03625828@googlegroups.com>
In reply to#90714
On Saturday, May 16, 2015 at 8:22:05 AM UTC+5:30, Rustom Mody wrote:
> On Saturday, May 16, 2015 at 6:54:23 AM UTC+5:30, Ned Batchelder wrote:
> > On Friday, May 15, 2015 at 8:57:53 PM UTC-4, Steven D'Aprano wrote:
> > > On Sat, 16 May 2015 05:41 am, Thomas 'PointedEars' Lahn wrote:
> > > 
> > > > 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.
> > > > 
> > > > <http://www.catb.org/~esr/faqs/smart-questions.html>
> > > 
> > > There ought to be a website that explains how to give smart answers.
> > 
> > Or one that explains how to be kind to those that don't know
> > the ropes yet.  Though pointing impatient experts at a
> > website probably won't get them to change any more than
> > brusquely pointing newbs at a website will.
> 
> How about a 'answerer-quota' 😇 ?
> 
> « Once for every 20 useful answers you are allowed to vent on any subject of 
>   your choice...
> 
>   - Stupid questions (and point to catb's smart questions)
>   - Google groups
>   - Top posting
>   - Html mail
> 
> »

Forgot the most important:   Using print's 😎

[toc] | [prev] | [next] | [standalone]


#90718

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2015-05-16 04:49 +0100
Message-ID<mailman.60.1431748175.17265.python-list@python.org>
In reply to#90714
On 16/05/2015 03:51, Rustom Mody wrote:
> On Saturday, May 16, 2015 at 6:54:23 AM UTC+5:30, Ned Batchelder wrote:
>> On Friday, May 15, 2015 at 8:57:53 PM UTC-4, Steven D'Aprano wrote:
>>> On Sat, 16 May 2015 05:41 am, Thomas 'PointedEars' Lahn wrote:
>>>
>>>> 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.
>>>>
>>>> <http://www.catb.org/~esr/faqs/smart-questions.html>
>>>
>>> There ought to be a website that explains how to give smart answers.
>>
>> Or one that explains how to be kind to those that don't know
>> the ropes yet.  Though pointing impatient experts at a
>> website probably won't get them to change any more than
>> brusquely pointing newbs at a website will.
>
> How about a 'answerer-quota' 😇 ?
>
> « Once for every 20 useful answers you are allowed to vent on any subject of
>    your choice...
>
>    - Stupid questions (and point to catb's smart questions)
>    - Google groups
>    - Top posting
>    - Html mail
>

Blatant discrimination against people who live in Mudeford, which of 
course straddles the mighty River Mude.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#90735

FromCecil Westerhof <Cecil@decebal.nl>
Date2015-05-16 15:49 +0200
Message-ID<87382wfx8p.fsf@Equus.decebal.nl>
In reply to#90686
Op Friday 15 May 2015 20:17 CEST schreef Cecil Westerhof:

> 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.

I found something. I could use:
    import sys

    sys.tracebacklimit = 10

The output is different, but I find it useful enough.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web