You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

process_tester.py 1.0KB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. """Test program for processes."""
  2. import sys, os
  3. # Twisted is unimportable from this file, so just do the PY3 check manually
  4. if sys.version_info < (3, 0):
  5. _PY3 = False
  6. else:
  7. _PY3 = True
  8. test_file_match = "process_test.log.*"
  9. test_file = "process_test.log.%d" % os.getpid()
  10. def main():
  11. f = open(test_file, 'wb')
  12. if _PY3:
  13. stdin = sys.stdin.buffer
  14. stderr = sys.stderr.buffer
  15. stdout = sys.stdout.buffer
  16. else:
  17. stdin = sys.stdin
  18. stdout = sys.stdout
  19. stderr = sys.stderr
  20. # stage 1
  21. b = stdin.read(4)
  22. f.write(b"one: " + b + b"\n")
  23. # stage 2
  24. stdout.write(b)
  25. stdout.flush()
  26. os.close(sys.stdout.fileno())
  27. # and a one, and a two, and a...
  28. b = stdin.read(4)
  29. f.write(b"two: " + b + b"\n")
  30. # stage 3
  31. stderr.write(b)
  32. stderr.flush()
  33. os.close(stderr.fileno())
  34. # stage 4
  35. b = stdin.read(4)
  36. f.write(b"three: " + b + b"\n")
  37. # exit with status code 23
  38. sys.exit(23)
  39. if __name__ == '__main__':
  40. main()