Python:有什么方法可以让一个进程拥有一个写锁而其他进程只是并行读取? [英] Python : Any way to get one process to have a write lock and others to just read on parallel?

查看:19
本文介绍了Python:有什么方法可以让一个进程拥有一个写锁而其他进程只是并行读取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个包含键值的字典,其中的值是一个带锁的对象.每个进程都需要获取锁来修改特定的对象,但是字典中的键是稳定的.

Let's say I have a dictionary that contains key-values where the value is an object with a lock. Each process needs to get the lock to modify the specific object, but the keys in the dictionary are stable.

现在,正如我之前所说,如果要为新对象添加新密钥(不经常),有没有办法使用锁来排除其他进程在我添加对象时访问这些对象字典的钥匙?

Now, as I said before, if a new key is to be added with a new object (not very often), is there a way to use a lock that will exclude the other processes from accessing the objects while I add the key to dictionary?

这样做的原因是,当所有进程不太可能对相同的对象进行操作时,我看不出将字典设置为对所有进程独占的意义,因此对象是唯一需要等待的对象在.当我修改字典的完整性时,我想阻止每个进程访问它,但虽然不是,我希望它们可以并行访问它.

The reason for this, is that I can't see the point in making the dictionary exclusive to all processes when it is unlikely that they will operate on the same objects, so the objects are the only ones that need to be waited on. When I modify the integrity of the dictionary, I want to block every process from accessing it, but while not, I want them to have parallel access to it.

如果我不清楚,请询问.

Please ask if I am not clear.

推荐答案

我找到了这些python版本的reader writer lock

I found these python version of the reader writer lock

Python 的读写锁

读写锁优先对于作家(Python 食谱)

这篇关于Python:有什么方法可以让一个进程拥有一个写锁而其他进程只是并行读取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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