title: Threading and conditions : debugging the acquirement
body: <p>I have a weird issue in one of my program, where a thread acquire a condition and an other thread tell that the condition is not acquired.</p>
  
  <p>I made some debug informations in order to know if the thread has acquired the condition, and it looks like yes, he did. But the other thread tell me that the condition is not acquired.</p>
  
  <p>Here is a summary (not really short, sorry about that) about how I did that, and the output I have :</p>
  
  <pre><code>import logging
  import time
  from threading import Condition, Lock, Thread
  logging.basicConfig(level=logging.DEBUG)
  
  class MyClass:
  
      def __init__(self):
  
          self._is_alive = False
          self._thread_update = None
          self._conditioned_thread = None
          self._thread_condition = Condition(Lock()) # Or RLock() or nothing, same issue
  
      def start(self):
  
          self._is_alive = True
          self._thread_update = Thread(target=self._loop_update, name="Updater")
          self._conditioned_thread = Thread(target=self._loop_conditioned, name="Conditioned")
          self._thread_update.start()
          self._conditioned_thread.start()
  
      def _loop_conditioned(self):
          logging.debug("Starting conditioned thread")
  
          with self._thread_condition:
              while self._is_alive:
                  logging.debug("Awaiting... Is acquired ? %s", self._thread_condition._is_owned())
                  self._thread_condition.wait()
                  logging.debug("Success !")
  
      def _loop_update(self):
          time.sleep(1)
          logging.debug("Notifying ! Is acquired ? %s", self._thread_condition._is_owned())
          self._thread_condition.notify(1)
          # Do some stuff
  
      def stop(self):
  
          self._is_alive = False
          self._thread_condition.notify()
          self._thread_update.join()
          self._thread_condition.join()
  
  if __name__ == "__main__":
      c = MyClass()
      c.start()
      time.sleep(4)
      c.stop()
  </code></pre>
  
  <p>And here is the output :</p>
  
  <pre><code>DEBUG:root:Starting conditioned thread
  DEBUG:root:Awaiting... Is acquired ? True
  DEBUG:root:Notifying ! Is acquired ? False
  Exception in thread Updater:
  Traceback (most recent call last):
    File "/usr/lib64/python2.6/threading.py", line 532, in __bootstrap_inner
      self.run()
    File "/usr/lib64/python2.6/threading.py", line 484, in run
      self.__target(*self.__args, **self.__kwargs)
    File ".../test.py", line 39, in _loop_update
      self._thread_condition.notify(1)
    File "/usr/lib64/python2.6/threading.py", line 274, in notify
      raise RuntimeError("cannot notify on un-acquired lock")
  RuntimeError: cannot notify on un-acquired lock
  
  Traceback (most recent call last):
    File ".../test.py", line 53, in &lt;module&gt;
      c.stop()
    File ".../test.py", line 45, in stop
      self._thread_condition.notify()
    File "/usr/lib64/python2.6/threading.py", line 274, in notify
      raise RuntimeError("cannot notify on un-acquired lock")
  RuntimeError: cannot notify on un-acquired lock
  </code></pre>
  
  <p>The question is why do I have RuntimeError on that, even if I have acquired the condition ?</p>