annotate Lib/test/subprocessdata/fd_status.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents c27527dce71e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
66868
de05d846795e issue7213: Open the pipes used by subprocesses with the FD_CLOEXEC flag from
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
1 """When called as a script, print a comma-separated list of the open
85491
c27527dce71e Issue #18571: Merge duplicate test code
Victor Stinner <victor.stinner@gmail.com>
parents: 85307
diff changeset
2 file descriptors on stdout.
c27527dce71e Issue #18571: Merge duplicate test code
Victor Stinner <victor.stinner@gmail.com>
parents: 85307
diff changeset
3
c27527dce71e Issue #18571: Merge duplicate test code
Victor Stinner <victor.stinner@gmail.com>
parents: 85307
diff changeset
4 Usage:
c27527dce71e Issue #18571: Merge duplicate test code
Victor Stinner <victor.stinner@gmail.com>
parents: 85307
diff changeset
5 fd_stats.py: check all file descriptors
c27527dce71e Issue #18571: Merge duplicate test code
Victor Stinner <victor.stinner@gmail.com>
parents: 85307
diff changeset
6 fd_status.py fd1 fd2 ...: check only specified file descriptors
c27527dce71e Issue #18571: Merge duplicate test code
Victor Stinner <victor.stinner@gmail.com>
parents: 85307
diff changeset
7 """
66868
de05d846795e issue7213: Open the pipes used by subprocesses with the FD_CLOEXEC flag from
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
8
de05d846795e issue7213: Open the pipes used by subprocesses with the FD_CLOEXEC flag from
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
9 import errno
de05d846795e issue7213: Open the pipes used by subprocesses with the FD_CLOEXEC flag from
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
10 import os
85307
fed15a462aa5 Use new new stat.S_ISDOOR() function, instead of hardcoded mask
Victor Stinner <victor.stinner@gmail.com>
parents: 68088
diff changeset
11 import stat
85491
c27527dce71e Issue #18571: Merge duplicate test code
Victor Stinner <victor.stinner@gmail.com>
parents: 85307
diff changeset
12 import sys
66868
de05d846795e issue7213: Open the pipes used by subprocesses with the FD_CLOEXEC flag from
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
13
de05d846795e issue7213: Open the pipes used by subprocesses with the FD_CLOEXEC flag from
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
14 if __name__ == "__main__":
68088
f5e9c17b85ad Issue #10826: Prevent sporadic failure in test_subprocess on Solaris due
Antoine Pitrou <solipsis@pitrou.net>
parents: 66868
diff changeset
15 fds = []
85491
c27527dce71e Issue #18571: Merge duplicate test code
Victor Stinner <victor.stinner@gmail.com>
parents: 85307
diff changeset
16 if len(sys.argv) == 1:
c27527dce71e Issue #18571: Merge duplicate test code
Victor Stinner <victor.stinner@gmail.com>
parents: 85307
diff changeset
17 try:
c27527dce71e Issue #18571: Merge duplicate test code
Victor Stinner <victor.stinner@gmail.com>
parents: 85307
diff changeset
18 _MAXFD = os.sysconf("SC_OPEN_MAX")
c27527dce71e Issue #18571: Merge duplicate test code
Victor Stinner <victor.stinner@gmail.com>
parents: 85307
diff changeset
19 except:
c27527dce71e Issue #18571: Merge duplicate test code
Victor Stinner <victor.stinner@gmail.com>
parents: 85307
diff changeset
20 _MAXFD = 256
c27527dce71e Issue #18571: Merge duplicate test code
Victor Stinner <victor.stinner@gmail.com>
parents: 85307
diff changeset
21 test_fds = range(0, _MAXFD)
c27527dce71e Issue #18571: Merge duplicate test code
Victor Stinner <victor.stinner@gmail.com>
parents: 85307
diff changeset
22 else:
c27527dce71e Issue #18571: Merge duplicate test code
Victor Stinner <victor.stinner@gmail.com>
parents: 85307
diff changeset
23 test_fds = map(int, sys.argv[1:])
c27527dce71e Issue #18571: Merge duplicate test code
Victor Stinner <victor.stinner@gmail.com>
parents: 85307
diff changeset
24 for fd in test_fds:
68088
f5e9c17b85ad Issue #10826: Prevent sporadic failure in test_subprocess on Solaris due
Antoine Pitrou <solipsis@pitrou.net>
parents: 66868
diff changeset
25 try:
f5e9c17b85ad Issue #10826: Prevent sporadic failure in test_subprocess on Solaris due
Antoine Pitrou <solipsis@pitrou.net>
parents: 66868
diff changeset
26 st = os.fstat(fd)
f5e9c17b85ad Issue #10826: Prevent sporadic failure in test_subprocess on Solaris due
Antoine Pitrou <solipsis@pitrou.net>
parents: 66868
diff changeset
27 except OSError as e:
f5e9c17b85ad Issue #10826: Prevent sporadic failure in test_subprocess on Solaris due
Antoine Pitrou <solipsis@pitrou.net>
parents: 66868
diff changeset
28 if e.errno == errno.EBADF:
f5e9c17b85ad Issue #10826: Prevent sporadic failure in test_subprocess on Solaris due
Antoine Pitrou <solipsis@pitrou.net>
parents: 66868
diff changeset
29 continue
f5e9c17b85ad Issue #10826: Prevent sporadic failure in test_subprocess on Solaris due
Antoine Pitrou <solipsis@pitrou.net>
parents: 66868
diff changeset
30 raise
f5e9c17b85ad Issue #10826: Prevent sporadic failure in test_subprocess on Solaris due
Antoine Pitrou <solipsis@pitrou.net>
parents: 66868
diff changeset
31 # Ignore Solaris door files
85307
fed15a462aa5 Use new new stat.S_ISDOOR() function, instead of hardcoded mask
Victor Stinner <victor.stinner@gmail.com>
parents: 68088
diff changeset
32 if not stat.S_ISDOOR(st.st_mode):
68088
f5e9c17b85ad Issue #10826: Prevent sporadic failure in test_subprocess on Solaris due
Antoine Pitrou <solipsis@pitrou.net>
parents: 66868
diff changeset
33 fds.append(fd)
f5e9c17b85ad Issue #10826: Prevent sporadic failure in test_subprocess on Solaris due
Antoine Pitrou <solipsis@pitrou.net>
parents: 66868
diff changeset
34 print(','.join(map(str, fds)))