title: Python - how to terminate a threading.Timer class correctly?
body: <p>I'm currently experimentating around with threading.Timer, and somehow I'm not doing very well..
  My goal is to run hundreds of functions, repeating all the time.
  The problem is, that the usage of my RAM is growing and growing and growing, until the process stops.</p>
  
  <p>This is how my code looks like:</p>
  
  <pre><code>from threading import Timer
  
  class Foo:
      def __init__(self, number):
          self.number = number
          self.timer = Timer(1, self.print_number)
          self.timer.start()
  
      def print_number(self):
          print "Number: %s"%self.number
          self.repeat()
  
      def repeat(self):
          self.timer.cancel()
          #self.timer.join()
          #time.sleep(1)
          self.timer = Timer(3, self.print_number)
          self.timer.start()
  
  for x in range(1, 300):
      Foo(x)
  </code></pre>
  
  <p>So, I've read that I can terminate a thread using .join() method after .cancel().
  But when I do this I'm getting a <code>RuntimeError: (cannot join current thread)</code>.
  On a similar topic I've read that I can use time.sleep after .cancel() to terminate a thread,
  but that does nothing to the thread for me.</p>
  
  <p>My questions: How can I properly terminate the threads in this code example and how can I stop the script from using more and more RAM, or am I doing something terribly wrong?</p>
  
  <p>Sorry if I'm re-asking a question that has been asked already many times, but I'm searching and trying for hours and couldn't find a solution yet.</p>
  
  <p>Thanks in advance.</p>