Christian Heimes added the comment:

In case someone is wondering if the approach really reduces the amount of 
syscalls: yes, it does. readdir() doesn't do a syscall for each entry. On Linux 
it uses the internal syscall getdents() to fill a buffer of directory entry 
structs. http://man7.org/linux/man-pages/man2/getdents.2.html

On my system os.listdir() does four syscalls:

$ strace python -c "import os; os.listdir('/home/heimes')"

openat(AT_FDCWD, "/home/heimes", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
getdents(3, /* 381 entries */, 32768)   = 12880
getdents(3, /* 0 entries */, 32768)     = 0
close(3)

On Linux you can also use /proc/self/fd instead of /proc/YOURPID/fd.

Other operating systems have different APIs to get a list of open FDs. AFAK 
/dev/fd is static on FreeBSD and Mac OS X:

FreeBSD:
  
http://www.manualpages.de/FreeBSD/FreeBSD-7.4-RELEASE/man3/kinfo_getfile.3.html

Darwin / Mac OS X:
  proc_pidinfo()

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13788>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to