1 | n/a | # Helper script for test_tempfile.py. argv[2] is the number of a file |
---|
2 | n/a | # descriptor which should _not_ be open. Check this by attempting to |
---|
3 | n/a | # write to it -- if we succeed, something is wrong. |
---|
4 | n/a | |
---|
5 | n/a | import sys |
---|
6 | n/a | import os |
---|
7 | n/a | from test.support import SuppressCrashReport |
---|
8 | n/a | |
---|
9 | n/a | with SuppressCrashReport(): |
---|
10 | n/a | verbose = (sys.argv[1] == 'v') |
---|
11 | n/a | try: |
---|
12 | n/a | fd = int(sys.argv[2]) |
---|
13 | n/a | |
---|
14 | n/a | try: |
---|
15 | n/a | os.write(fd, b"blat") |
---|
16 | n/a | except OSError: |
---|
17 | n/a | # Success -- could not write to fd. |
---|
18 | n/a | sys.exit(0) |
---|
19 | n/a | else: |
---|
20 | n/a | if verbose: |
---|
21 | n/a | sys.stderr.write("fd %d is open in child" % fd) |
---|
22 | n/a | sys.exit(1) |
---|
23 | n/a | |
---|
24 | n/a | except Exception: |
---|
25 | n/a | if verbose: |
---|
26 | n/a | raise |
---|
27 | n/a | sys.exit(1) |
---|