puellavulnerata: (girl geek), by <lj site="livejournal.com" user="sp4z26">
[personal profile] puellavulnerata

Python compiles source files to byte code automatically whenever a module is imported; to save itself time, it does this only if the bytecode file (.pyc) does not exist or has an mtime older than the corresponding source file.

Reasonable enough so far; now here's the stupid: if the corresponding source file no longer exists but the bytecode file has been left in place, python will silently use the bytecode. Suppose we have script.py and module.py in one directory, and another module.py elsewhere on the search path, so the local module.py overrides the other one. Now suppose, after this has been run at least once and module.pyc has been created in the local directory, module.py is deleted; in the work-related example I'm thinking of, module.py was a different implementation of uuid, and the silliness that motivated it eventually went away.

It turns out that, in this case, Python check if the mtime on the source file is newer than the mtime on the bytecode file, but fails to check for the continued existence of the source file, leading me to some mysterious exceptions, a wasted fifteen minutes of bafflement and a large *facepalm*.

Profile

puellavulnerata: (cthulhu)
puellavulnerata

March 2011

S M T W T F S
  1 2345
6789101112
13141516171819
20212223242526
2728293031  

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 23rd, 2012 04:27 pm
Powered by Dreamwidth Studios