Error message repetition

Thomas Jollans thomas at jollans.com
Wed Jul 7 11:28:25 EDT 2010


On 07/07/2010 05:10 PM, Tambet wrote:
> Hello!
> 
> I have such problem that:
> 
>     * My console shows maximally x last lines, then truncates
>     * Error message takes 2 line
>     * In case of very big stack trace, there will be 2*x error lines
>     * In such case I do not see any debug output
> 
> In this case, it's about recursion:
> 
>   File "b2.py", line 124, in seek_solution
>     solution = self.seek_solution(weight + U.gravity, len(test), test)
>   File "b2.py", line 124, in seek_solution
>     solution = self.seek_solution(weight + U.gravity, len(test), test)
>   File "b2.py", line 124, in seek_solution
>     solution = self.seek_solution(weight + U.gravity, len(test), test)
>   File "b2.py", line 124, in seek_solution
>     solution = self.seek_solution(weight + U.gravity, len(test), test)
>   File "b2.py", line 124, in seek_solution
>     solution = self.seek_solution(weight + U.gravity, len(test), test)
>   File "b2.py", line 124, in seek_solution
>     solution = self.seek_solution(weight + U.gravity, len(test), test)
> and so on...

Depending on how far this goes up, you might just be able to change the
backlog your terminal emulator saves? that would allow you to scroll up.
If you can't do that, you should get a proper console.

Anyway, if you want to customise the traceback output, you can!
simply replace sys.excepthook with your own version.

http://docs.python.org/dev/py3k/library/sys.html#sys.excepthook

> 
> I think it should be instead:
>   File "b2.py", line 124, in seek_solution [*repeated x times*]
>     solution = self.seek_solution(weight + U.gravity, len(test), test)
> 
> Getting big strack trace is most probable with functions calling
> themselves - thus, long stack traces usually contain such repetitions.
> 
> As those functions might not call themselves directly, one cycle of
> recursion might become four lines long, in such case:
> 
> Stack item 1:  File "b2.py", line 124, in seek_solution
>     solution = self.seek_solution(weight + U.gravity, len(test), test)
> Stack item 2:  File "b2.py", line 124, in seek_solution
>     solution = self.seek_solution(weight + U.gravity, len(test), test)
> Stack item repetitions: [#1, #2] * x
> 
> This could simply enumerate stack items and then create formulas of
> repetitions, like:
> [[#1, #2] * 15, #3 * 15] * 3
> 
> If it shows each message written-out at least one and max two or three
> times, but over that gives it an id and shows patterns of those instead,
> it will be a lot better. I have, sometimes, gone through some four pages
> of Java stack traces etc., but I think that having such long array of
> errors does not make it more readable or simple - if you can see
> everything in one page, then it's good enough for pondering. And
> scrolling up and looking at output would be a nice feature ;) Especially
> now, as I am going to raise recursion limit - this program would be
> perfectly possible without relying on built-in loop constructions so
> much, but I did it yesterday in such manner and it simply raised into
> unmanageable complexity. Thus, now I am trying to encapsulate it's logic
> into pieces, which maximize the use of Pythons overloads and
> function-based iterators etc., but this makes error messages that long
> when I do something wrong - and I can't even check if that was really
> some mistake in code or just the recursion actually needs to be deeper
> than I hoped.
> 
> Tambet
> 




More information about the Python-list mailing list