|
- from threading import Thread
- import multiprocessing as mp
- import time
- import random
- from queue import Queue
-
- inputQueue = mp.Queue(10)
- inputQueue2 = mp.Queue(10)
-
- class ProducerThread(Thread):
- global inputQueue
- def run(self):
- numbers = range(40)
- while True:
- num = random.choice(numbers)
- inputQueue.put(num)
- print("\nPut",num)
- time.sleep(.05)
-
- class ConsumerProcess1(mp.Process):
- global inputQueue
- def run(self):
- while True:
- num = inputQueue.get()
- print("\nGot", num)
- time.sleep(.1)
-
- class ConsumerProcess2(mp.Process):
- global
-
-
- if __name__ == "__main__":
- print("this is example 2")
- time.sleep(2)
- a=ProducerThread()
- b=ConsumerProcess1()
-
- a.start()
- b.start()
-
-
- a.join()
- b.join()
|