[Python-ideas] os.listdir iteration support
aahz at pythoncraft.com
Fri Nov 23 05:59:02 CET 2007
On Thu, Nov 22, 2007, Giampaolo Rodola' wrote:
> I would find very useful having a version of os.listdir returning a
> generator. If a directory has many files, say 20,000, it could take
> a long time getting all of them with os.listdir and this could be a
> problem in asynchronous environments (e.g. asynchronous servers).
> The only solution which comes to my mind in such case is using a
> thread/fork or having a non-blocking version of listdir() returning an
> What do you think about that?
The problem is that reading a directory requires an open file handle;
given a generator context, there's no clear mechanism for determining
when to close the handle. Because the list needs to be created in the
first place, why bother with a generator?
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"Typing is cheap. Thinking is expensive." --Roy Smith
More information about the Python-ideas