statcache.lstat?
Does this (untested) code make sense as a possible addition to statcache? One obvious problem I see is that if stat(path) had been called before lstat(path), you'd pull the wrong info out of the cache. You could get around this by maintaining separate stat and lstat caches or caching a different key (e.g. (path, "l")) for the lstat variety. If this is deemed worthwhile I'll make it work and submit a patch to SF. I wanted to check first to make sure I wasn't missing something obvious that would keep it from ever working. Skip *** /tmp/skip/statcache.py.~1.11~fVASKs Wed Oct 31 13:10:22 2001 --- /tmp/skip/statcache.pyfVAfUy Wed Oct 31 13:10:22 2001 *************** *** 6,12 **** import os as _os from stat import * ! __all__ = ["stat","reset","forget","forget_prefix","forget_dir", "forget_except_prefix","isdir"] # The cache. Keys are pathnames, values are os.stat outcomes. --- 6,12 ---- import os as _os from stat import * ! __all__ = ["stat","lstat","reset","forget","forget_prefix","forget_dir", "forget_except_prefix","isdir"] # The cache. Keys are pathnames, values are os.stat outcomes. *************** *** 22,27 **** --- 22,37 ---- if ret is None: cache[path] = ret = _os.stat(path) return ret + + if hasattr(_os, "lstat"): + def lstat(path): + """Lstat a file, possibly out of the cache.""" + ret = cache.get(path, None) + if ret is None: + cache[path] = ret = _os.lstat(path) + return ret + else: + lstat = stat def reset(): """Clear the cache."""
Does this (untested) code make sense as a possible addition to statcache?
For me, statcache was a failed experiment. What's the use you have in mind? Why can't you use os.lstat() directly?
One obvious problem I see is that if stat(path) had been called before lstat(path), you'd pull the wrong info out of the cache. You could get around this by maintaining separate stat and lstat caches or caching a different key (e.g. (path, "l")) for the lstat variety.
Definitely use two caches or a separate key. --Guido van Rossum (home page: http://www.python.org/~guido/)
>> Does this (untested) code make sense as a possible addition to >> statcache? Guido> For me, statcache was a failed experiment. What's the use you Guido> have in mind? Why can't you use os.lstat() directly? I can use os.lstat (or os.stat) directly. I'm working on a file selector widget written in Python (and PyGtk). As people traverse the directory tree, it seems to make sense to cache the stat results. If statcache is indeed a failed experiment, perhaps it should be deprecated. Skip
Guido> For me, statcache was a failed experiment. What's the use you Guido> have in mind? Why can't you use os.lstat() directly?
I can use os.lstat (or os.stat) directly. I'm working on a file selector widget written in Python (and PyGtk). As people traverse the directory tree, it seems to make sense to cache the stat results.
But why bother? And why not let them see changes in the filesystem?
If statcache is indeed a failed experiment, perhaps it should be deprecated.
Fine with me. --Guido van Rossum (home page: http://www.python.org/~guido/)
>> I can use os.lstat (or os.stat) directly. I'm working on a file >> selector widget written in Python (and PyGtk). As people traverse >> the directory tree, it seems to make sense to cache the stat results. Guido> But why bother? And why not let them see changes in the Guido> filesystem? File selector goodies peek at all files in a directory, even the stuff you don't care about, at the very least to segregate them into directory and non-directory files. Caching stat info would probably help speed them up. I was trying to speed things up a bit and saw statcache. I had been using os.stat and os.lstat, so it was natural to wonder about the absence of statcache.lstat. Maybe it's best to simply rely on the underlying operating system's caching. >> If statcache is indeed a failed experiment, perhaps it should be >> deprecated. Guido> Fine with me. Here's a proposed addition to PEP 4: Module name: statcache Rationale: Of limited usefulness and complicates the life of the application programmer, who must manage the cache. Not widely used by other core libraries (they use os.stat instead). Also, it is not thread-safe. Date: 31-Oct-2001 Documentation: TBD Just say the word and I'll update it and submit a patch for the documentation. Oh, and congratulations on the imminent arrival. You will kill for a nice nap in a couple weeks. ;-) Skip
Here's a proposed addition to PEP 4:
Module name: statcache Rationale: Of limited usefulness and complicates the life of the application programmer, who must manage the cache. Not widely used by other core libraries (they use os.stat instead). Also, it is not thread-safe. Date: 31-Oct-2001 Documentation: TBD
Just say the word and I'll update it and submit a patch for the documentation.
If others on python-dev agree they can give the word. --Guido van Rossum (home page: http://www.python.org/~guido/)
participants (3)
-
barry@zope.com
-
Guido van Rossum
-
Skip Montanaro