proc3.py 573 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env python
  2. from multiprocessing import Process, Queue
  3. from mybutt import generate_primes, generate_fibs
  4. def primes(q):
  5. for prime in generate_primes():
  6. q.put(('prime', prime))
  7. def fibs(q):
  8. for fib in generate_fibs():
  9. q.put(('fib', fib))
  10. if __name__ == '__main__':
  11. q = Queue()
  12. pp = Process(target=primes, args=(q,))
  13. fp = Process(target=fibs, args=(q,))
  14. pp.start()
  15. fp.start()
  16. while True:
  17. # print out primes and fibonaccis
  18. # as fast as they can be calculated
  19. x = q.get()
  20. print x