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


Groups > comp.lang.python > #7183

Re: Function call arguments in stack trace?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Neil Cerutti <neilc@norwich.edu>
Newsgroups comp.lang.python
Subject Re: Function call arguments in stack trace?
Date 7 Jun 2011 20:29:47 GMT
Organization Norwich University
Lines 47
Message-ID <957g1rF32aU1@mid.individual.net> (permalink)
References <9d344c45-8017-4c80-9a17-bc7accd81047@l26g2000yqm.googlegroups.com> <9578lmFl76U1@mid.individual.net> <6c3c9ab9-7880-4988-8258-8f8b2d4d7f72@m21g2000yqc.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Trace individual.net 7ZTH2I1J2EU/+/1SBlvLcgSe4eFepHOYIChaiIQRtRnBSPKqFR
Cancel-Lock sha1:4NSnahNJtjrcasfDHacs83lYtLw=
User-Agent slrn/0.9.9p1/mm/ao (Win32)
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7183

Show key headers only | View raw


On 2011-06-07, Dun Peal <dunpealer@gmail.com> wrote:
> On Jun 7, 1:23?pm, Neil Cerutti <ne...@norwich.edu> wrote:
>> Use pdb.
>
> Neil, thanks for the tip; `pdb` is indeed a great debugging
> tool.
>
> Still, it doesn't obviate the need for arguments in the stack
> trace. For example:
>
> 1) Arguments in stack trace can expedite a debugging session, and even
> obviate it completely: "Why did `foo()` fail?  Oh, because it got `-1`
> as its first argument, while I only coded for positive integers!".
> 2) In some environments, it's very hard to recreate a rare exception
> and analyze it with `pdb`. For instance, on a web application that
> emails the stack traces of unhandled exceptions, it's very important
> for that stack trace to be as informative as possible, since often
> that's the only debugging feedback you will get.
>
> Hope that makes sense, D.

The locals should be in the frame object of the traceback. Here's
a sketch of a decorator to print them out before your program
bombs:

import sys

def report_arg_info(fn):
    def wrapper(*arg, **kw):
        try:
            return fn(*arg, **kw)
        except:
            frame = sys.exc_info()[2].tb_next.tb_frame
            print(frame.f_locals)
            raise
    return wrapper

Use it as usual:

@report_arg_info
def my_func(bombs)
    raise ValueError

You could log the local arguments instead.

-- 
Neil Cerutti

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


Thread

Function call arguments in stack trace? Dun Peal <dunpealer@gmail.com> - 2011-06-07 11:09 -0700
  Re: Function call arguments in stack trace? Neil Cerutti <neilc@norwich.edu> - 2011-06-07 18:23 +0000
    Re: Function call arguments in stack trace? Dun Peal <dunpealer@gmail.com> - 2011-06-07 12:31 -0700
      Re: Function call arguments in stack trace? Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-07 13:52 -0600
      Re: Function call arguments in stack trace? Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2011-06-07 22:01 +0200
      Re: Function call arguments in stack trace? Neil Cerutti <neilc@norwich.edu> - 2011-06-07 20:29 +0000
  Re: Function call arguments in stack trace? "Gabriel Genellina" <gagsl-py2@yahoo.com.ar> - 2011-06-07 23:45 -0300

csiph-web