ยปCore Development>Code coverage>Lib/test/subprocessdata/fd_status.py

Python code coverage for Lib/test/subprocessdata/fd_status.py

#countcontent
1n/a"""When called as a script, print a comma-separated list of the open
2n/afile descriptors on stdout.
3n/a
4n/aUsage:
5n/afd_stats.py: check all file descriptors
6n/afd_status.py fd1 fd2 ...: check only specified file descriptors
7n/a"""
8n/a
9n/aimport errno
10n/aimport os
11n/aimport stat
12n/aimport sys
13n/a
14n/aif __name__ == "__main__":
15n/a fds = []
16n/a if len(sys.argv) == 1:
17n/a try:
18n/a _MAXFD = os.sysconf("SC_OPEN_MAX")
19n/a except:
20n/a _MAXFD = 256
21n/a test_fds = range(0, _MAXFD)
22n/a else:
23n/a test_fds = map(int, sys.argv[1:])
24n/a for fd in test_fds:
25n/a try:
26n/a st = os.fstat(fd)
27n/a except OSError as e:
28n/a if e.errno == errno.EBADF:
29n/a continue
30n/a raise
31n/a # Ignore Solaris door files
32n/a if not stat.S_ISDOOR(st.st_mode):
33n/a fds.append(fd)
34n/a print(','.join(map(str, fds)))