I was thinking about using a class variable as a thread lock, since I don't like to define a lock within the global variables and also want to prevent deadlock. Does this actually work? Example:
import threading
class A(object):
lock = threading.Lock()
a = 1
@classmethod
def increase_a(cls):
with cls.lock:
cls.a += 1
Considering I would not re-assign the A.lock
variable somewhere inside or outside the class, my assumption would be that it is treated the same as a global lock? Is this correct?