python多进程实现共享变量

from multiprocessing import Process, Queue, Manager

def deal_data():
    
    with lock:
        dictValues['num'] -= 1
    print dictValues['num']

if __name__ == '__main__':

    dictValues = Manager().dict()
    lock = Manager().Lock()
    dictValues["num"] = 1000000

    process_list = []
    for i in range(20):
        process_list.append(Process(target=deal_data, args=(dictValues,lock)))
    for j in process_list:
        j.start()

 

你可能感兴趣的:(python)