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

deluxstar deluxstar at gmail.com
Sat Sep 25 03:53:13 EDT 2010


On 24 Eylül, 12:39, Peter Otten <__pete... at web.de> wrote:
> deluxstar wrote:
> > We have an application working on several servers generally written
> > with Python 2.6 and Twisted 10.
> > The source codes are located in one server and compiled in this
> > server. The compiled files are copied to other server via network and
> > application server works with these compiled files.
>
> > In this application, I have to write a function to return a value of
> > the caller object that calles this function. The function may be
> > called from several modules of the application. To achieve this goal,
> > I try to use the python inspect module:
>
> > curframe = inspect.currentframe()
> > calframe = inspect.getouterframes(curframe, 2)
> > calframe[1][0].f_locals['variable']
>
> > This sample code works on local development environment both on linux
> > and windows. When checked in to production environment,
> > inspect.currentframe() or inspect.stack() function gives "List index
> > out of range error".
>
> > When I googled, I found only one clue of copying pyc files:
> >http://forum.webfaction.com/viewtopic.php?pid=16808
>
> > Why inspect modules gives this error? OR Is there another way to get
> > the caller objects variable value?
>
> Can you provide the actual traceback? Provide a small script that reproduces
> the error? Add print statements and post their output?
>
> print inspect.currentframe> curframe = inspect.currentframe()
> print curframe
> > calframe = inspect.getouterframes(curframe, 2)
>
> print calframe
>
> Peter

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

It is hard to reproduce the error with a script. I will work and send
if I success.
If the traceback tells smth, please tell me :)
Thnx



More information about the Python-list mailing list