import threading
data = [ ] # Some data
lck = threading.Lock() # Create a lock
def put_obj(obj):
lck.acquire()
data.append(obj)
lck.release()
def get_obj():
lck.acquire()
r = data.pop()
lck.release()
return r
Only one thread is allowed to acquire the lock at once
Most useful for coordinating access to shared data.