[Python-Dev] Import redesign [LONG]

Skip Montanaro skip@mojam.com (Skip Montanaro)
Fri, 19 Nov 1999 16:34:42 -0600


Gordon wrote:

    Gordon> I posted something here about dircache not too long ago.
    Gordon> Essentially, I found it completely unreliable on NT and on Linux
    Gordon> to stat the directory. There was some test code attached.

to which I replied:

    Skip> The modtime of the directory's stat info should only change if you
    Skip> add or delete entries in the directory.  Were you perhaps
    Skip> expecting changes when other operations took place, like rewriting
    Skip> an existing file?

I took a couple minutes to write a simple script to check things.  It
created a file, changed its mode, then unlinked it.  I was a bit surprised
that deleting a file didn't appear to change the directory's mod time.  Then
I realized that since file times are only recorded with one-second
precision, you might see no change to the directory's mtime in some
circumstances.  Adding a sleep to the script between directory operations
resolved the apparent inconsistency.  Still, as Gordon stated, you probably
can't count on directory modtimes to tell you when to invalidate the cache.
It's consistent, just not reliable...

if-we-slow-import-down-enough-we-can-use-this-trick-though-ly y'rs,

Skip Montanaro | http://www.mojam.com/
skip@mojam.com | http://www.musi-cal.com/
847-971-7098   | Python: Programming the way Guido indented...