[Python-Dev] Updates to PEP 471, the os.scandir() proposal (original) (raw)
Ben Hoyt benhoyt at gmail.com
Wed Jul 9 17:35:26 CEST 2014
- Previous message: [Python-Dev] Updates to PEP 471, the os.scandir() proposal
- Next message: [Python-Dev] Updates to PEP 471, the os.scandir() proposal
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
One issue with option #2 that I just realized -- does scandir yield the entry at all if there's a stat error? It can't really, because the caller will expect the .lstat attribute to be set (assuming he asked for type='lstat') but
it won't be. Is effectively removing these entries just because the stat failed a problem? I kind of think it is. If so, is there a way to solve it with option #2? Leave it up to the onerror handler. If it returns None, skip yielding the entry, otherwise yield whatever it returned -- which also means the error handler should be able to set fields on the DirEntry: def logerr(exc, entry): logger.warn("Cannot stat {}".format(exc.filename)) entry.lstat.stsize = 0 return True
This is an interesting idea, but it's just getting more and more complex, and I'm guessing that being able to change the attributes of DirEntry will make the C implementation more complex.
Also, I'm not sure it's very workable. For log_err above, you'd actually have to do something like this, right?
def log_err(exc, entry): logger.warn("Cannot stat {}".format(exc.filename)) entry.lstat = os.stat_result((0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) return entry
Unless there's another simple way around this issue, I'm back to loving the simplicity of option #1, which avoids this whole question.
-Ben
- Previous message: [Python-Dev] Updates to PEP 471, the os.scandir() proposal
- Next message: [Python-Dev] Updates to PEP 471, the os.scandir() proposal
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]