[Python-Dev] dircache.py

Gordon McMillan gmcm@hypernet.com
Sun, 31 Oct 1999 10:59:16 -0500

Pursuant to my volunteering to implement Guido's plan to 
combine cmp.py, cmpcache.py, dircmp.py and dircache.py 
into filecmp.py, I did some investigating of dircache.py.

I find it completely unreliable. On my NT box, the mtime of the 
directory is updated (on average) 2 secs after a file is added, 
but within 10 tries, there's always one in which it takes more 
than 100 secs (and my test script quits). My Linux box hardly 
ever detects a change within 100 secs.

I've tried a number of ways of testing this ("this" being 
checking for a change in the mtime of the directory), the latest 
of which is below. Even if dircache can be made to work 
reliably and surprise-free on some platforms, I doubt it can be 
done cross-platform. So I'd recommend that it just get dropped.


import os
import sys
import time
d = os.getcwd()
atimes = []

def test():
    m = os.stat(d)[8]
    for i in range(10):
        fnm = 's%d.tmp' % i
        open(fnm,'w').write('dummy - delete me')
        for j in range(10000):
            newm = os.stat(d)[8]
            if newm != m:
                m = newm
            print "At round %d, failed to detect add within %3.2f 
secs" % (i, j*0.01)

def report():
    import operator
    if atimes:
        print "detect adds:   min= %3.2f max= %3.2f avg= 
%3.2f" % (min(atimes), max(atimes), reduce(operator.add, 
atimes, 0.0)/len(atimes))
        print "no successfully detected adds"


- Gordon