File paths printed in stack trace are where Python was built???

R

Roy Smith

We distribute Python internally by building it in one place, and then
distributing images of the entire install area to wherever it's
needed. I just noticed something strange; when I got an error which
caused a stack trace, the file paths in the printed stack trace refer
to the directory where Python was built.

Why is this? All other paths I can think of in Python are generated
relative to where the binary is running, not where it was built. Is
there a way to make the stacktraces point to where Python is running
from, instead of where it was built?


Traceback (most recent call last):
File "tProcess.py", line 27, in test_t1
server = subprocess.Popen(argv)
File "/emc/chacoj2/src/clean/smarts/thirdparty/python/2.5.1/
linux_rhAS40-x86-32/install/lib/python2.5/subprocess.py", line 593, in
__init__
errread, errwrite)
File "/emc/chacoj2/src/clean/smarts/thirdparty/python/2.5.1/
linux_rhAS40-x86-32/install/lib/python2.5/subprocess.py", line 1079,
in _execute_child
raise child_exception
AttributeError: 'list' object has no attribute 'rfind'
 
S

Steven D'Aprano

We distribute Python internally by building it in one place, and then
distributing images of the entire install area to wherever it's needed.
I just noticed something strange; when I got an error which caused a
stack trace, the file paths in the printed stack trace refer to the
directory where Python was built.

My guess is that your build process generates the .pyc files, and that
they include a reference to the source location at the time they were
built. I bet that if you remove the .pyc files and let them get re-
generated the problem will go away.
Is there a way to make the stacktraces point to where Python is
running from, instead of where it was built?

But the stack trace doesn't point to where Python is running from, it
points to where the module is. Since you're (probably) running from a
compiled module, the location of the .pyc file is useless, and you need
to know where the .py file is. But how can the .pyc file know where
the .py file is at runtime unless it is cached at compile time? I suppose
Python could use some sort of heuristic to guess, but that would be slow
and error-prone.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top