From: tamino |
Date: September 24th, 2008 05:26 am (UTC) |
| (Link) |
|
Nope -- if you look at what inspect.getframeinfo is doing, it's getting it from f_lineno (as well as doing a bunch of other work to assemble information that you're discarding, and the gathering of which will slow things down)
You may be thinking of the f_lineno member of the python frame struct in C. You're right that that doesn't get updated on every line, but if you access it from within python, yes, it'll make sure it's up to date before it returns the value to you.
Incidentally, in gdb, where you *do* have to worry about these issues, I use:
p (char *)(((PyStringObject *)f->f_code->co_filename)->ob_sval) p PyCode_Addr2Line(f->f_code, f->f_lasti)
the latter of which does the actual magic to get the correct line number (f->f_lineno will likely be out of date).
|