title: Why is this singleton implementation "not thread safe"?
body: <h2>1. The @Singleton decorator</h2>
  
  <p>I found an elegant way to decorate a Python class to make it a <code>singleton</code>. The class can only produce one object. Each <code>Instance()</code> call returns the same object:</p>
  
  <pre><code>class Singleton:
      """
      A non-thread-safe helper class to ease implementing singletons.
      This should be used as a decorator -- not a metaclass -- to the
      class that should be a singleton.
  
      The decorated class can define one `__init__` function that
      takes only the `self` argument. Also, the decorated class cannot be
      inherited from. Other than that, there are no restrictions that apply
      to the decorated class.
  
      To get the singleton instance, use the `Instance` method. Trying
      to use `__call__` will result in a `TypeError` being raised.
  
      """
  
      def __init__(self, decorated):
          self._decorated = decorated
  
      def Instance(self):
          """
          Returns the singleton instance. Upon its first call, it creates a
          new instance of the decorated class and calls its `__init__` method.
          On all subsequent calls, the already created instance is returned.
  
          """
          try:
              return self._instance
          except AttributeError:
              self._instance = self._decorated()
              return self._instance
  
      def __call__(self):
          raise TypeError('Singletons must be accessed through `Instance()`.')
  
      def __instancecheck__(self, inst):
          return isinstance(inst, self._decorated)
  </code></pre>
  
  <p>I found the code here:
  <a href="https://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons">Is there a simple, elegant way to define singletons?</a></p>
  
  <p>The comment at the top says:</p>
  
  <blockquote>
    <p>[This is] a non-thread-safe helper class to ease implementing singletons.</p>
  </blockquote>
  
  <p>Unfortunately, I don't have enough multithreading experience to see the 'thread-unsafeness' myself.</p>
  
  <p>&nbsp;<br></p>
  
  <h2>2. Questions</h2>
  
  <p>I'm using this <code>@Singleton</code> decorator in a multithreaded Python application. I'm worried about potential stability issues. Therefore:</p>
  
  <ol>
  <li><p>Is there a way to make this code completely thread-safe?</p></li>
  <li><p>If the previous question has no solution (or if its solution is too cumbersome), what precautions should I take to stay safe?</p></li>
  <li><p>@Aran-Fey pointed out that the decorator is badly coded. Any improvements are of course very much appreciated.</p></li>
  </ol>
  
  <hr>
  
  <p><sub>Hereby I provide my current system settings:<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&#62;&nbsp; Python 3.6.3<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&#62;&nbsp; Windows 10, 64-bit<br>
  </sub></p>