RLock Objects

The RLock object

  • A mutual-exclusion lock that allows repeated acquisition by the same thread
  • Allows nested acquire(), release() operations in the thread that owns the lock.
  • Only the outermost release() operation actually releases the lock.
     import threading
     data = [ ]                  # Some data
     lck = threading.Lock()      # Create a lock
     
     def put_obj(obj):
         lck.acquire()
         data.append(obj)
         ...
         put_obj(otherobj)       # Some kind of recursion
         ...
         lck.release()
     
     def get_obj():
         lck.acquire()
         r = data.pop()
         lck.release()
         return r 
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 75
July 17, 2000, beazley@cs.uchicago.edu
>>>