From: Zac Medico Date: Sun, 28 Apr 2013 22:39:24 +0000 (-0700) Subject: get_open_fds: use /dev/fd or /proc/self/fd X-Git-Tag: v2.2.0_alpha174~10 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=154e490e5064733a139eae72ed37192016dcb52f;p=portage.git get_open_fds: use /dev/fd or /proc/self/fd Since /dev/fd is supposed to be a fairly standard unix feature, try that first. --- diff --git a/pym/portage/process.py b/pym/portage/process.py index f00775cf5..24e347c26 100644 --- a/pym/portage/process.py +++ b/pym/portage/process.py @@ -30,10 +30,15 @@ except ImportError: if sys.hexversion >= 0x3000000: basestring = str -if os.path.isdir("/proc/%i/fd" % os.getpid()): +for _fd_dir in ("/dev/fd", "/proc/self/fd"): + if os.path.isdir(_fd_dir): + break + else: + _fd_dir = None + +if _fd_dir is not None: def get_open_fds(): - return (int(fd) for fd in os.listdir("/proc/%i/fd" % os.getpid()) \ - if fd.isdigit()) + return (int(fd) for fd in os.listdir(_fd_dir) if fd.isdigit()) if platform.python_implementation() == 'PyPy': # EAGAIN observed with PyPy 1.8.