[Python-Dev] Mysterious Python pyc file corruption problems (original) (raw)

Guido van Rossum guido at python.org
Thu May 16 23:19:14 CEST 2013


This reminds me of the following bug, which can happen when two processes are both writing the .pyc file and a third is reading it. First some background.

When writing a .pyc file, we use the following strategy:

Even py_compile.py (used by compileall.py) uses this strategy.

When reading a .pyc file, we ignore it when the magic word isn't there (or when the mtime doesn't match that of the .py file exactly), and then we will write it back like described above.

Now consider the following scenario. It involves three processes.

Now, this would explain the EOFError, but not necessarily the ValueError with "unknown type code". However, it looks like marshal doesn't always check for EOF immediately (sometimes it calls getc() without checking the result, and sometimes it doesn't check the error state after calling r_string()), so I think all the errors are actually explainable from this scenario.

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



More information about the Python-Dev mailing list