Re: Caches, caches...

jredford@lehman.com
Fri, 18 Mar 94 08:52:53 -0500

>> From: Sjoerd Mullender <Sjoerd.Mullender@cwi.nl>
>> Subject: Re: Caches, caches...

>> On Wed, Mar 16 1994 Guido.van.Rossum@cwi.nl wrote:
>>
>> > > This brings up another interesting point: are the .pyc files guarded agains
>> > t
>> > > concurrent generation?
>> >
>> > Yes. The timestamp and magic number are written last, in one write
>> > operation.
>>
>> As stated, this is not enough. It can happen that two processes start
>> writing the same .pyc file at the same time. I suppose that usually
>> the two processes will write identical copies, but when there are
>> different versions of python around, that may not be the case.
>>
>> A better approach would be to write to a temporary file first and
>> linking the temporary file to the .pyc file at the end. When linking
>> fails, someone else was there before you, so you can ignore the error.

And and even better approach would be to open module.pid, write out
the file, close it, then rename(2) module.pid to module.'pyc', on
POSIXy systems and something similar elsewhere.

I dont know what you meant by linking, but there is always the case
where someone was 'there before you' and wrote the old version of a
pyc, and you need to write a new version, since the .py changed. There
is no point in not over-writing what was already there, assuming it
can be done atomically.

--
John Redford (AKA GArrow) | 3,600 hours of tape.
jredford@lehman.com       | 5 cans of Scotchguard.