zl程序教程

您现在的位置是:首页 >  其它

当前栏目

Lock objects should only be shared between processes through inheritance

be lock Only between shared should Objects Through
2023-09-14 08:57:14 时间

python的进程同步需要使用multiprocessing.Manager类型的对象来构造,普通的Lock不行

def main():
    iterable = [1, 2, 3, 4, 5]
    pool = multiprocessing.Pool()
    m = multiprocessing.Manager()
    l = m.Lock()
    func = partial(target, l)
    pool.map(func, iterable)
    pool.close()
    pool.join()