blob: 92ebd95e5236869ef3a4eabe5f8a170412e7e042 [file] [log] [blame]
Guido van Rossum78741062002-08-17 11:41:01 +00001# 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
7
8verbose = (sys.argv[1] == 'v')
9try:
10 fd = int(sys.argv[2])
11
12 try:
Antoine Pitrou9cadb1b2008-09-15 23:02:56 +000013 os.write(fd, b"blat")
Guido van Rossum78741062002-08-17 11:41:01 +000014 except os.error:
15 # Success -- could not write to fd.
16 sys.exit(0)
17 else:
18 if verbose:
19 sys.stderr.write("fd %d is open in child" % fd)
20 sys.exit(1)
21
Guido van Rossumcd16bf62007-06-13 18:07:49 +000022except Exception:
Guido van Rossum78741062002-08-17 11:41:01 +000023 if verbose:
24 raise
25 sys.exit(1)