title: Creating a 'singleton' thread- How to have at most 1 instance of a thread at any one time
body: <p>I'm looking to have a class (subclassed from threading.Thread) that is initialised and started from multiple places in a program. What I want to avoid is if the thread is already running from somewhere else, if another place in the program trys to start it</p>
  
  <pre><code>t= somemodule.TheThread(some,args)
  t.start()
  </code></pre>
  
  <p>the program can carry on (but the thread only starts if the same thread isn't already running here, or elsewhere).</p>
  
  <p>I can think of a few not very elegant ways to achieve this with setting flags, but there must be a nice way of dealing with this. I looked at singleton type patterns with decorators or overriding <strong>new</strong> but the main problem is that if I keep the same instance is that you can't (that I'm aware) call start more than once, even if the thread has finished.</p>
  
  <p>I thought about having the thread object created in anther object which can check to see if the current thread is still running, but I couldn't work out how to keep this thread safe.</p>
  
  <p>Anyone got any ideas?</p>