Mysterious Python pyc file corruption problems

Barry Warsaw barry at
Thu May 16 15:29:02 UTC 2013

Well, that sucks.  These two cases break my hypothesis.

>>> I've found one bug where the interpreter is python3.3:

So, let's assume that the traceback is accurate.  It's telling us that Python
3.3 is unable to import optparse, which is a stdlib module and so should have
gotten its pyc written when python3.3-minimal was installed.  In the bug, I've
asked to have /usr/lib/python3.3/__pycache__/optparse.cpython-33.pyc
attached.  If nothing has changed since the original bug report, and that *is*
the corrupt file, we should be able to inspect it and at least verify the

>>> This looks to be a fresh install of Raring so the apport data seems 
>>> trustworthy.  (There are some apport issues with delayed reporting and 
>>> distribution upgrades.)  I'll be doing a full search of Launchpad bugs 
>>> shortly.
>> And

This one is trickier, since the failing import is:

  File "/usr/lib/python3/dist-packages/apport/", line 12, in <module>
    import subprocess, tempfile, os.path, re, pwd, grp, os

All of these are in python3.3-minimal, and all but pwd and grp are Python
modules (those latter two are extension modules, so wouldn't have any pyc
files to get corrupted).  I'll ask the OP to attach the relevant .pyc files
for verification.

>would it be possible to find out for each bug report which file seems to be
>corrupt, and which package it belongs too?  To see if this breakage is limited
>to certain packages. So far for the two bugs mentioned it's python3.3-minimal,
>and python3-apport.

I wonder if we can instrument apport to catch these types of errors
specifically, analyze the failing import lines, and chase them back to the pyc
files that appear to be the culprits?

It's not just stdlib modules getting corrupted though.  Maybe py_compile or
some other part of the byte-compile-after-installation toolchain is
misbehaving under some situations?  But the Python 3.3 cases lead away from
the race-condition-on-writing-pyc file theory.


More information about the ubuntu-devel mailing list