首页 > 其他分享 >Lock objects should only be shared between processes through inheritance

Lock objects should only be shared between processes through inheritance

时间:2023-01-11 17:37:35浏览次数:36  
标签:processes inheritance Lock through iterable multiprocessing pool

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

 

标签:processes,inheritance,Lock,through,iterable,multiprocessing,pool
From: https://www.cnblogs.com/2018shawn/p/17044425.html

相关文章