When closing the connection to a database, we often receive the following error:
UnboundLocalError: local variable 'conn' referenced before assignment
Looking at the code for the DBAPI class, we see the following error:
def close(self): if not hasattr(self, '_pool'): # Probably there was an exception while creating this # instance, so it is incomplete. return if not self._pool: return self._poolLock.acquire() try: conns = self._pool[:] self._pool[:] =  for conn in conns: try: conn.close() except self.module.Error: pass del conn <<< MISSING INDENT del conns finally: self._poolLock.release()
Log in to post a comment.