Module baldy compiled to pyc?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Thu Sep 27 07:13:04 EDT 2012
On Thu, 27 Sep 2012 11:00:36 +0200, Laszlo Nagy wrote:
> Today I had a strange experience. I have copied some updated py files
> (modules) to a directory on a remote server, overwritting the old ones.
> The pyc files on the server were older. Many programs are importing
> these modules, and most of them are started as background jobs (from
> cron). They started to throw all kinds of errors. I checked the py
> files, and they did have class definitions inside. However when I tried
> to use them I got AttributeError exceptions. Telling that those things
> are not in the module.
It sounds to me like the timestamps on the .py files were messed up when
you copied them, causing Python to prefer old, broken .pyc files instead
of the newer .py files.
> I suspect that there were two (or more) programs starting at the same
> time, writting the same pyc file at the same time.
I suppose that's not impossible, although you would need to check the
Python source code to be sure. But I would expect that each process
writes the .pyc file atomically, so even if two processes both try to
create the .pyc file, one will harmlessly overwrite the other's output. I
would be surprised if it were possible for two processes to
simultaneously write to the same file -- that would require the Python
compiler to explicitly open the .pyc file in shared writable mode, and
why would it do that?
Far more likely is a file system error. I recommend you run a disk check
on the file server and see if it comes up with any errors.
--
Steven
More information about the Python-list
mailing list