Python 多进程本机共享内存(二)

#-*- coding:utf8 -*-

from multiprocessing import Process,sharedctypes
from time import sleep

class Work:

    def __init__(self):
        self.Process = Process
        self.num = sharedctypes.Value("i",1)

    def producter(self):
        self.add()


    def consumer(self):
        self.add()

    def add(self):
        self.num.value += 1


    def start(self):
        self.Process(target=self.producter).start()
        self.Process(target=self.consumer).start()
        sleep(1)
        print self.num.value

if __name__ == '__main__':
    W = Work()
    W.start()

 

转载于:https://my.oschina.net/CandyMi/blog/752090

评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符 “速评一下”
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页