inspect.stack() or inspect.currentframe() gives "list index out of range error"

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Sep 25 10:25:51 CEST 2010


On Sat, 25 Sep 2010 00:53:13 -0700, deluxstar wrote:

> The traceback is:
> 2010-09-25 10:50:38+0300 [-] Traceback (most recent call last):
> 2010-09-25 10:50:38+0300 [-]   File "../appsrv/lqcommon.py", line 983,
> in getPRMS
> 2010-09-25 10:50:38+0300 [-]   File "/usr/lib/python2.6/inspect.py",
> line 931, in getouterframes
> 2010-09-25 10:50:38+0300 [-]     framelist.append((frame,) +
> getframeinfo(frame, context))
> 2010-09-25 10:50:38+0300 [-]   File "/usr/lib/python2.6/inspect.py",
> line 906, in getframeinfo
> 2010-09-25 10:50:38+0300 [-]     lines, lnum = findsource(frame)
> 2010-09-25 10:50:38+0300 [-]   File "/usr/lib/python2.6/inspect.py",
> line 568, in findsource
> 2010-09-25 10:50:38+0300 [-]     if pat.match(lines[lnum]): break
> 2010-09-25 10:50:38+0300 [-] IndexError: list index out of range

I'm going to take a wild guess here.

My guess is that you've copied the .pyc file onto the server, BUT there 
is also an *older* version of the .py file there as well. Because the 
modification date is older than that of the .pyc file, Python executes 
the compiled code from the .pyc file. But when you search for the source 
code, the old .py file is discovered -- but it doesn't have the right 
number of lines, and so you end up with an IndexError.



-- 
Steven



More information about the Python-list mailing list