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