[root@localhost /]#
[root@localhost /]# cat zhu.py
#!/bin/python
import multiprocessing
import random
import time
import os
def producer(pipe):
while True:
time.sleep(1)
item = random.randint(1, 10)
print('process producer product goods:{}'.format(item))
pipe.send(item)
time.sleep(1)
def consumer(pipe):
while True:
time.sleep(1)
item = pipe.recv()
print('process cusumer get goods:{}'.format(item))
time.sleep(1)
if __name__ == "__main__":
pipe = multiprocessing.Pipe()
process_producer = multiprocessing.Process( target=producer, args=(pipe[0],))
process_consumer = multiprocessing.Process( target=consumer, args=(pipe[1],))
process_producer.start()
process_consumer.start()
process_producer.join()
process_consumer.join()
[root@localhost /]#
阅读(2161) | 评论(0) | 转发(0) |