All pastes #923564 Raw Edit

Stuff

public text v1 · immutable
#923564 ·published 2008-02-29 17:38 UTC
rendered paste body
def countOpenFileDescriptors():
    import resource
    soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
    n = 0
    for fd in range(soft):
        try:
            os.fstat(fd)
            n += 1
        except OSError, e:
            if e.errno != errno.EBADF:
                n += 1
        except Exception:
            pass
    return n