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


Groups > comp.lang.python > #21249

Re: Error with co_filename when loading modules from zip file

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <bob@brasko.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'elif': 0.04; 'interpreter': 0.05; 'subject:Error': 0.05; 'computed': 0.07; 'paths': 0.07; 'subject:when': 0.07; 'python': 0.08; 'correct.': 0.09; 'filename': 0.09; 'imho.': 0.09; 'match.': 0.09; 'subject:modules': 0.09; 'variables,': 0.09; 'files.': 0.09; 'stored': 0.13; 'subject:file': 0.13; 'yet.': 0.15; '.py': 0.16; 'guessing': 0.16; 'patch,': 0.16; 'sajip': 0.16; 'suggestions?': 0.16; 'url:hg': 0.16; 'vinay': 0.16; 'cc:addr:python-list': 0.16; 'mon,': 0.16; 'url:bugs': 0.17; 'wrote:': 0.18; 'computing': 0.18; 'issue,': 0.18; 'trace': 0.18; 'issue.': 0.19; 'thanks,': 0.19; '(which': 0.19; 'compiled': 0.21; 'cc:no real name:2**0': 0.21; 'file,': 0.21; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'library.': 0.24; 'stack': 0.24; 'expect': 0.25; 'cc:2**0': 0.26; 'module': 0.26; 'skip:_ 20': 0.26; 'load': 0.26; 'function': 0.27; 'tried': 0.27; 'variable': 0.28; 'putting': 0.28; "i'm": 0.28; 'compile': 0.29; 'problem': 0.29; 'cc:addr:python.org': 0.29; 'seem': 0.29; 'skip:p 30': 0.29; 'ran': 0.30; 'file.': 0.31; 'source': 0.32; 'determined': 0.32; 'skip:l 30': 0.32; "i've": 0.32; "isn't": 0.33; 'header:User-Agent:1': 0.33; 'file': 0.34; 'done': 0.34; 'calling': 0.34; 'frame': 0.34; 'probably': 0.35; 'moving': 0.35; 'url:python': 0.35; 'received:209.85.160': 0.36; 'two': 0.36; 'issue': 0.37; 'comparing': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'using': 0.37; 'subject:with': 0.37; 'skip:_ 10': 0.38; 'received:209.85': 0.38; 'could': 0.38; 'think': 0.38; 'files': 0.39; 'received:209.85.160.46': 0.39; 'received:mail-pw0-f46.google.com': 0.39; 'url:org': 0.39; 'subject:from': 0.39; 'received:209': 0.39; 'might': 0.40; 'one,': 0.40; 'header:Received:6': 0.61; 'address': 0.61; 'efficient': 0.62; 'zip': 0.62; 'making': 0.64; 'recompile': 0.84; '3.3': 0.91; 'to:addr:yahoo.co.uk': 0.91
Received-SPF pass (google.com: domain of bob@brasko.net designates 10.68.236.35 as permitted sender) client-ip=10.68.236.35;
Authentication-Results mr.google.com; spf=pass (google.com: domain of bob@brasko.net designates 10.68.236.35 as permitted sender) smtp.mail=bob@brasko.net
Date Mon, 5 Mar 2012 21:14:08 -0500
From Bob Rossi <bob@brasko.net>
To Vinay Sajip <vinay_sajip@yahoo.co.uk>
Subject Re: Error with co_filename when loading modules from zip file
References <mailman.410.1330979936.3037.python-list@python.org> <c1e15a96-3e77-4d7e-b684-d1b8a2bd49b1@p13g2000yqd.googlegroups.com>
MIME-Version 1.0
Content-Type text/plain; charset=iso-8859-1
Content-Disposition inline
Content-Transfer-Encoding 8bit
In-Reply-To <c1e15a96-3e77-4d7e-b684-d1b8a2bd49b1@p13g2000yqd.googlegroups.com>
User-Agent Mutt/1.5.21 (2010-09-15)
X-Gm-Message-State ALoCoQkAB61clcJ3nrP9xfUgOHhKu/vpUvvsNbA8IwdyNXMbWf98pf5JkT7GcawcAudKu6osmS4O
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.416.1331000185.3037.python-list@python.org> (permalink)
Lines 58
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1331000185 news.xs4all.nl 6949 [2001:888:2000:d::a6]:59695
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:21249

Show key headers only | View raw


On Mon, Mar 05, 2012 at 02:22:55PM -0800, Vinay Sajip wrote:
> On Mar 5, 8:36 pm, Bob <b...@brasko.net> wrote:
> 
> > The logging package gets the filename and line number
> > of the calling function by looking at two variables, the filename
> > of the frame in the stack trace and the variable logging._srcfile.
> > The comparison is done in logging/__init__.py:findCaller.
> >
> 
> The _srcfile is computed in logging/__init__.py - can you see which of
> the paths it takes when computing _srcfile?

Yes, it's this one,
elif __file__[-4:].lower() in ['.pyc', '.pyo']:
    _srcfile = __file__[:-4] + '.py'

_srcfile I beleive is correct. It's filename that isn't IMHO.

> > I've tried putting only the pyc files, only the py files
> > and both in the zip file.
> 
> I think the filename info might be stored in the .pyc from when you
> ran it outside the .zip. If you delete all .pyc files and only
> have .py in the .zip, what happens?

Nice one.

I tried putting only pyc file, only py files and both
in the zip. But I never tried putting the py files in the zip
and deleting the pyc files. That makes it work as I'm guessing
it has to recompile the python bytecode, making the filename
and _srcfile match.

The problem with this approach, is that it's less efficient
to store the pyc files, since I've got to recompile them
on startup, right?

I found this issue,
  http://bugs.python.org/issue6811
and this related patch,
  http://hg.python.org/cpython/rev/5deb2094f033
that I think might address this issue. Although that's using 3.3
which isn't released yet.

This is probably an issue that could be addressed in the logging
library.  Comparing the compiled in filename
(which is determined at compile time) and the source file name
(which is determined at module load time) doesn't seem to
play well when you are moving the interpreter around in a zip file.
I don't think one would expect it to.

One solution would be to look to see if the filename ends in
pythonNM[.zip]/logging/__init__.py

Any suggestions?

Thanks,
Bob

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


Thread

Error with co_filename when loading modules from zip file Bob <bob@brasko.net> - 2012-03-05 15:36 -0500
  Re: Error with co_filename when loading modules from zip file Vinay Sajip <vinay_sajip@yahoo.co.uk> - 2012-03-05 14:22 -0800
    Re: Error with co_filename when loading modules from zip file Bob Rossi <bob@brasko.net> - 2012-03-05 21:14 -0500
    Re: Error with co_filename when loading modules from zip file Bob Rossi <bob@brasko.net> - 2012-03-05 21:40 -0500
      Re: Error with co_filename when loading modules from zip file Vinay Sajip <vinay_sajip@yahoo.co.uk> - 2012-03-06 02:38 -0800
        Re: Error with co_filename when loading modules from zip file Bob Rossi <bob@brasko.net> - 2012-03-06 08:41 -0500
        Re: Error with co_filename when loading modules from zip file Peter Otten <__peter__@web.de> - 2012-03-06 14:59 +0100

csiph-web