为什么python多处理管理器会产生线程锁? [英] Why python multiprocessing manager produce threading locks?

查看:61
本文介绍了为什么python多处理管理器会产生线程锁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<预><代码>>>>导入多处理>>>multiprocessing.Manager().Lock()<0x7f64f7736290处的thread.lock对象>>>>类型(多处理.锁定())<类'multiprocessing.synchronize.Lock'>

为什么管理器生成的对象是 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屋!

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