title: How to initialize Singleton-derived object once
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons-in-python">Is there a simple, elegant way to define Singletons in Python?</a>  </p>
  </blockquote>
  
  
  
  <p>I have the following example code, in which I derive a class from a Singleton (hope it is one):</p>
  
  <pre><code>class Singleton(object):
      _instance = None
      def __new__(cls, *args, **kwargs):
          if not cls._instance:
              cls._instance = object.__new__(cls, *args, **kwargs)
          return cls._instance
  
  class Tracer(Singleton):         
      def __init__(self):
          print "Init"
  
  a = Tracer()
  b = Tracer()
  </code></pre>
  
  <p>When you try it, you will see the <code>__init__</code> method of <code>Tracer</code> is called again. Isn't the sense of having a singleton to make another instance refer to the original one? I do not want to run the <code>__init__</code> method again, as it probably overwrites previous information. Maybe the singleton is wrong or it's use?</p>