有什么理由要使用threading.Lock而不是multiprocessing.Lock吗? [英] Is there any reason to use threading.Lock over multiprocessing.Lock?

查看:279
本文介绍了有什么理由要使用threading.Lock而不是multiprocessing.Lock吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果软件项目支持将多处理反向移植到的Python版本,那么是否有理由在multiprocessing.Lock上使用threading.Lock? multiprocessing锁也不是线程安全的吗?

If a software project supports a version of Python that multiprocessing has been backported to, is there any reason to use threading.Lock over multiprocessing.Lock? Would a multiprocessing lock not be thread safe as well?

为此,是否有理由使用threading中的任何同步原语(也位于multiprocessing中)?

For that matter, is there a reason to use any synchronization primitives from threading that are also in multiprocessing?

推荐答案

线程模块的同步原语比多处理程序更轻巧,速度更快,这是因为它没有处理共享信号量等.使用线程的锁.进程应使用多重处理的锁.

The threading module's synchronization primitive are lighter and faster than multiprocessing, due to the lack of dealing with shared semaphores, etc. If you are using threads; use threading's locks. Processes should use multiprocessing's locks.

这篇关于有什么理由要使用threading.Lock而不是multiprocessing.Lock吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆