[Python-Dev] PEP 428: stat caching undesirable?
christian at python.org
Wed May 1 18:22:34 CEST 2013
Am 01.05.2013 16:39, schrieb Guido van Rossum:
> I've not got the full context, but I would like to make it *very*
> clear in the API (e.g. through naming of the methods) when you are
> getting a possibly cached result from stat(), and I would be very
> concerned if existing APIs were going to get caching behavior. For
> every use cases that benefits from caching there's a complementary use
> case that caching breaks. Since both use cases are important we must
> offer both APIs, in a way that makes it clear to even the casual
> reader of the code what's going on.
I deem caching of stat calls as problematic. The correct and
contemporary result of a stat() call has security implications, too. For
example stat() is used to prevent TOCTOU race conditions such as .
Caching is useful but I would prefer explicit caching rather than
implicit and automatic caching of stat() results.
We can get a greater speed up for walkdir() without resorting to
caching, too. Some operating systems and file system report the file
type in the dirent struct that is returned by readdir(). This reduces
the number of stat calls to zero.
More information about the Python-Dev