title: How does python Rlock work and what is the owner of Rlock?
body: <p>I am currently practicing python multi-thread module, and I write some code as below, but it is not working as I just expect.</p>
  
  <pre><code>import threading
  import thread
  import random
  import time
  lock = threading.RLock()
  def func(lock):
      print("In Thread " + threading.currentThread().getName())
      lock.acquire()
      time.sleep(random.random()*10)
      lock.release()
      print("Out Thread " + threading.currentThread().getName())
  
  def start():
      lock.acquire()
      for i in range(5):
          thread.start_new(func, (lock,))
      lock.release()
  
  # for i in range(5):
  #     thread.start_new(func, (lock,))
  start()
  
  print("test")
  time.sleep(1)
  lock.acquire()
  print("main ends")
  lock.release()
  </code></pre>
  
  <p>In my opinion, whether there is time.sleep(1) in the main thread does not count much for the new threads's running, because the lock is global and belongs to the main thread, the lock.acquire() operation would always work fine, so the main thread should not wait for those new threads to proceed. According to the property of thread.start_new(), when the main thread ends, all new threads would also stop. However, when I comment out the time.sleep() line, the program goes as what I have expected, but when I add this line in, the main thread always waits for new threads to finish.</p>
  
  <p>This confuses me a lot and hope someone would explain to me the functionality of Rlock() as well as which thread does it belong to when I create it in the main thread while passing it to the sub-new thread and calling lock.acquire()?</p>