Skip to content

Commit 3e37ccb

Browse files
committed
Add supporting dir subprocessdata
1 parent 4fcbe70 commit 3e37ccb

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed

Lib/test/subprocessdata/fd_status.py

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

Lib/test/subprocessdata/qcat.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""When ran as a script, simulates cat with no arguments."""
2+
3+
import sys
4+
5+
if __name__ == "__main__":
6+
for line in sys.stdin:
7+
sys.stdout.write(line)

Lib/test/subprocessdata/qgrep.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""When called with a single argument, simulated fgrep with a single
2+
argument and no options."""
3+
4+
import sys
5+
6+
if __name__ == "__main__":
7+
pattern = sys.argv[1]
8+
for line in sys.stdin:
9+
if pattern in line:
10+
sys.stdout.write(line)
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import signal, subprocess, sys, time
2+
# On Linux this causes os.waitpid to fail with OSError as the OS has already
3+
# reaped our child process. The wait() passing the OSError on to the caller
4+
# and causing us to exit with an error is what we are testing against.
5+
signal.signal(signal.SIGCHLD, signal.SIG_IGN)
6+
subprocess.Popen([sys.executable, '-c', 'print("albatross")']).wait()
7+
# Also ensure poll() handles an errno.ECHILD appropriately.
8+
p = subprocess.Popen([sys.executable, '-c', 'print("albatross")'])
9+
num_polls = 0
10+
while p.poll() is None:
11+
# Waiting for the process to finish.
12+
time.sleep(0.01) # Avoid being a CPU busy loop.
13+
num_polls += 1
14+
if num_polls > 3000:
15+
raise RuntimeError('poll should have returned 0 within 30 seconds')

0 commit comments

Comments
 (0)