title: Python, multi-threading - RuntimeError: cannot notify on un-acquired lock
body: <p>I want to create a simple code which is able to generate odd and even numbers by using multi-threading. There are many ways of doing it, but I am trying to implement a lock, mainly for learning purposes.
  Here's my code:</p>
  <pre><code>from threading import *
  from time import sleep
  
  class Even:
      def __init__(self):
          self.c = Condition()
  
      def evenNumbers(self):
          self.c.acquire()
          for i in range(0, 101, 2):
              print(&quot;Even : &quot;, i)
              self.num = i
              sleep(1.)
              self.c.notify()
              self.c.release()
              
              
  class Odd:
      def __init__(self, even):
          self.even = even
  
      def oddNumbers(self):
          self.even.c.acquire()
          print(&quot;Odd : &quot;, self.even.num+1)
          sleep(1.)
          self.even.c.notify()
          self.even.c.release()
  
  tEven = Even()
  tOdd = Odd(tEven)
  
  t1 = Thread(target=tEven.evenNumbers)
  t2 = Thread(target=tOdd.oddNumbers)
  
  t1.start()
  t2.start()
  </code></pre>
  <p>and I get the following error</p>
  <blockquote>
  <p>Exception in thread Thread-6:
  Traceback (most recent call last):
  File &quot;/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py&quot;, line 926, in _bootstrap_inner
  self.run()
  File &quot;/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py&quot;, line 870, in run
  self._target(*self._args, **self._kwargs)
  File &quot;&quot;, line 14, in evenNumbers
  self.c.notify()
  File &quot;/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py&quot;, line 346, in notify
  raise RuntimeError(&quot;cannot notify on un-acquired lock&quot;)
  RuntimeError: cannot notify on un-acquired lock</p>
  </blockquote>
  <p>Any ideas?</p>