tf_inherit_check.py 714 B

123456789101112131415161718192021222324252627
  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. import sys
  5. import os
  6. from test.support import SuppressCrashReport
  7. with SuppressCrashReport():
  8. verbose = (sys.argv[1] == 'v')
  9. try:
  10. fd = int(sys.argv[2])
  11. try:
  12. os.write(fd, b"blat")
  13. except OSError:
  14. # Success -- could not write to fd.
  15. sys.exit(0)
  16. else:
  17. if verbose:
  18. sys.stderr.write("fd %d is open in child" % fd)
  19. sys.exit(1)
  20. except Exception:
  21. if verbose:
  22. raise
  23. sys.exit(1)