有什么理由要使用threading.Lock而不是multiprocessing.Lock吗? [英] Is there any reason to use threading.Lock over 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屋!