为什么python多处理管理器会产生线程锁? [英] Why python multiprocessing manager produce threading locks?
问题描述
为什么管理器生成的对象是 thread.lock
而不是 multiprocessing.synchronize.Lock
,因为它应该来自 multiprocessing
代码>对象?
托管对象始终是代理;管理器的目标是使非多处理感知对象成为多处理感知对象.
对 multiprocessing.Lock()
对象这样做没有意义;这些是使用信号量实现的,并且无需帮助即可完全进行多处理.
threading.Lock
另一方面是不知道多处理的;threading.Lock()
对象和 multiprocessing.Lock()
之间有一些区别;例如,后者在获取锁时支持超时.
>>> import multiprocessing
>>> multiprocessing.Manager().Lock()
<thread.lock object at 0x7f64f7736290>
>>> type(multiprocessing.Lock())
<class 'multiprocessing.synchronize.Lock'>
Why the object produced by a manager is a thread.lock
and not a multiprocessing.synchronize.Lock
as it would be expected from a multiprocessing
object?
Managed objects are always proxies; the goal of the manager is to make non-multiprocessing-aware objects into multiprocessing aware.
There is no point in doing this for multiprocessing.Lock()
objects; these are implemented using semaphores and are fully multiprocessing capable without assistance.
threading.Lock
on the other hand is not multiprocessing aware; there are some differences between threading.Lock()
objects and multiprocessing.Lock()
; the latter supports a timeout when acquiring a lock, for example.
这篇关于为什么python多处理管理器会产生线程锁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!