[Python-checkins] r88224 - python/branches/test_subprocess_10826/Lib/test/subprocessdata/fd_status.py
antoine.pitrou
python-checkins at python.org
Sat Jan 29 11:09:15 CET 2011
Author: antoine.pitrou
Date: Sat Jan 29 11:09:15 2011
New Revision: 88224
Log:
Try to ignore Solaris door files in fd_status.py
Modified:
python/branches/test_subprocess_10826/Lib/test/subprocessdata/fd_status.py
Modified: python/branches/test_subprocess_10826/Lib/test/subprocessdata/fd_status.py
==============================================================================
--- python/branches/test_subprocess_10826/Lib/test/subprocessdata/fd_status.py (original)
+++ python/branches/test_subprocess_10826/Lib/test/subprocessdata/fd_status.py Sat Jan 29 11:09:15 2011
@@ -3,32 +3,22 @@
import errno
import os
-import fcntl
-import subprocess
-import sys
try:
_MAXFD = os.sysconf("SC_OPEN_MAX")
except:
_MAXFD = 256
-def isopen(fd):
- """Return True if the fd is open, and False otherwise"""
- try:
- fcntl.fcntl(fd, fcntl.F_GETFD, 0)
- except IOError as e:
- if e.errno == errno.EBADF:
- return False
- raise
- return True
-
if __name__ == "__main__":
- fds = [fd for fd in range(0, _MAXFD) if isopen(fd)]
+ fds = []
+ for fd in range(0, _MAXFD):
+ try:
+ st = os.fstat(fd)
+ except OSError as e:
+ if e.errno == errno.EBADF:
+ continue
+ raise
+ # Ignore Solaris door files
+ if st.st_mode & 0xF000 != 0xd000:
+ fds.append(fd)
print(','.join(map(str, fds)))
- if '--debug' in sys.argv[1:]:
- for fd in fds:
- print(fd, fcntl.fcntl(fd, fcntl.F_GETFL), os.fstat(fd))
- sys.stdout.flush()
- subprocess.call("ls -la /proc/{}/fd/".format(os.getpid()), shell=True)
- if 5 in fds:
- subprocess.call("stat /proc/{}/fd/{}".format(os.getpid(), 5), shell=True)
More information about the Python-checkins
mailing list