[Python-Dev] possible bug in python importing pyc files

Guido van Rossum guido at python.org
Tue Dec 1 19:05:43 CET 2009


What kind of failure do you get? A a failed test, a Python exception,
or a core dump?

Are you sure there is no code in your app or in your tests that looks
at __file__ and trips up over if it ends in '.pyc' instead of '.py' ?

Are you importing from zipfiles (e.g. eggs you've downloaded)?

Can you remember a time when this wasn't happening? Were you using a
different Python version then or was your application + tests
different? If it wasn't happening with an earlier version of Python,
please confirm -- this helps us believe that the problem isn't
somewhere in your app.

It would be very useful to isolate the problem to the existence or
non-existence of a single .pyc file -- if as you think there is a bug
in the .pyc reading or writing, it must be a very rare test and is
likely only triggered by one particular file.

The first step would probably be to boil down the problem to a
particular unit test. (If you are using Python's unittest.main()
driver, there are command line flags to run only a specific test, so
that should be easy enough.) Then remove all .pyc files, run the test
again, and see which .pyc files are created by running it. Then
confirm that the test fails. Then delete half the .pyc files and see
if the test still fails. You can then start bisecting by removing more
or fewer .pyc files until you've boiled it down to one particular .pyc
file. Then look at the source and see if there's something funny (e.g.
is it very long, or does it have a very long token or expression?).

On Tue, Dec 1, 2009 at 9:01 AM, Ram Bhamidipaty <rambham at gmail.com> wrote:
> Hi,
>
> I have some code that exhibits behavior that might be a python import bug.
>
> The code is part of a set of unit tests. One test in passes when no .pyc files
> exist, but fails when the pyc file is present on disk. My code is not doing any
> thing special with import or pickle or anything "fancy". I have confirmed the
> behavior in 2.6.4, as well the svn 2.6 version. The svn 2.7 version
> always fails.
> All builds were production builds (not debug).
>
> The code that shows this problem is owned by my company, I'm not sure
> if I would be able to produce it to create a bug report. But I do have some time
> to help debug the problem.
>
> What steps should I take to try to isolate the problem?
>
> Thanks for any info.
> -Ram
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org
>



-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list