python 管道符

2020-12-13 02:58

阅读:423

标签:style   pip   from   sleep   producer   print   pre   for   %s   

数据不安全,不常用

import time
from multiprocessing import Pipe, Process


def producer(prod, cons, name, food):
    cons.close()
    for i in range(10):
        f = %s生产%s%s % (name, food, i)
        prod.send(f)
        time.sleep(0.5)
        print(f)
    prod.close()


def consumer(prod, cons, name):
    prod.close()
    while 1:
        food = cons.recv()
        f = %s吃了%s % (name, food)
        time.sleep(0.7)
        print(f)


if __name__ == __main__:
    prod, cons = Pipe()
    p = Process(target=producer, args=(prod, cons, tom, 包子))
    p.start()
    c = Process(target=consumer, args=(prod, cons, joker))
    c.start()
    p.join()
    c.join()

 

python 管道符

标签:style   pip   from   sleep   producer   print   pre   for   %s   

原文地址:https://www.cnblogs.com/wt7018/p/11062478.html


评论


亲,登录后才可以留言!