title: Weakly referenced object no longer exists when trying to create a "destructor"
body: <p>am trying to create a MySQL database adaptor class for myself, and want to clean up when the object is destroyed.</p>
  <p>The init and del methods look something like this:</p>
  <pre><code>
      def __init__(self, database):
          self.connection = mysql.connector.connect(
              host = &quot;xxx&quot;,
              database = self.database,
              port = &quot;xxx&quot;,
              user = &quot;xxx&quot;,
              password = &quot;xxx&quot;,
          )
          self.cursor = self.connection.cursor()
  
      def __del__(self):
          self.cursor.close()
          self.connection.close()
  </code></pre>
  <p>But <code>self.cursor.close()</code> in <code>__del__()</code> will complain about a: <code>ReferenceError: weakly-referenced object no longer exists</code></p>
  <p>I've read the most related SO post I can find: <a href="https://stackoverflow.com/questions/1482141/what-does-it-mean-weakly-referenced-object-no-longer-exists">What does it mean &quot;weakly-referenced object no longer exists&quot;?</a></p>
  <p>And as far as I can tell I don't have any of the same issues that caused the asker of that question to be facing this weakly referenced object error.</p>
  <p>Some context on the app:<br />
  Using mysql.connector<br />
  Being instantiated while running a Flask app. (don't know if quitting does anything unique)</p>
  <p>Thanks all.</p>