title: Running a background thread in python
body: <p>All the examples I've been able to get to don't really address my problem, of having a certain procedure in the background constantly looping, while the rest of the program continues.</p>
  
  <p>Here is a simple example of a method that works, using _thread:</p>
  
  <pre><code>import _thread
  import time
  
  
  def countSeconds():
      time.sleep(1)
      print("Second")
      _thread.start_new(countSeconds, ())
  
  def countTenSeconds():
      time.sleep(10)
      print("Ten seconds passed")
      _thread.start_new(countTenSeconds, ())
  
  
  _thread.start_new(countSeconds, ())
  _thread.start_new(countTenSeconds, ())
  </code></pre>
  
  <p>Ignoring the obvious fact that we could track the seconds, and just print something different if it's a multiple of ten, how would I go about creating this more efficiently.</p>
  
  <p>In my actual program, the threading seems to be guzzling RAM, I assume from creating multiple instance of the thread. Do I have to "start_new" thread at the end of each procedure?</p>
  
  <p>Thanks for any help.</p>