proc4.py 516 B

123456789101112131415161718192021222324
  1. #!/usr/bin/env python
  2. from multiprocessing import Process, Pipe
  3. import random
  4. import sys
  5. def evaluator(p):
  6. while True:
  7. stuff = p.recv()
  8. # evaluate the stuff
  9. if random.random() > 0.2:
  10. p.send("it's awesome!")
  11. else:
  12. p.send("it sucked!")
  13. if __name__ == '__main__':
  14. parent_conn, child_conn = Pipe()
  15. p = Process(target=evaluator, args=(child_conn,))
  16. p.start()
  17. for x in sys.stdin:
  18. parent_conn.send(x)
  19. print parent_conn.recv()