You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Question: is the thread_local=False works only when use the same Lock instance?
(Here the 'work' means that in thread1 release a lock owned by thread2.)
I'm trying to reproduce the behavior here in the doc:
To share state when thread_local=False, you still need to use the same lock instance.
This is why the behavior in your example is expected.
When you call r.lock(lock_name, timeout=5, thread_local=False) a new lock object is created. The token information is stored in its self.local object, which is defined as: self.local = threading.local() if self.thread_local else SimpleNamespace()
Since thread_local=False, self.local is a SimpleNamespace() instance. This means attributes can be freely shared between threads but only within the same lock instance. If you create a second lock instance, it will have a separate SimpleNamespace() object, and the state will not be shared between the two locks.
Question: is the
thread_local=False
works only when use the same Lock instance?(Here the 'work' means that in thread1 release a lock owned by thread2.)
I'm trying to reproduce the behavior here in the doc:
redis-py/redis/lock.py
Lines 115 to 126 in 2fb2f47
Here is my first try(failed):
I got the output:
So it seems that I can not release the lock from Thread1 and the reason from error message is clear.
Then, I try to use a global Lock instance, and it works:
The output:
So I have the question at begin. I'm not sure the statement is accurate or not, any help will be appreciated!
The text was updated successfully, but these errors were encountered: