Lock objects should only be shared between processes through inheritance

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()

 

posted @ 2023-01-11 17:20  余生以学  阅读(366)  评论(0编辑  收藏  举报