'Close the connection to the database.'

def close(self):

    self.validate_thread_sharing()
    self.run_on_commit = []
    if (self.closed_in_transaction or (self.connection is None)):
        return
    try:
        self._close()
    finally:
        if self.in_atomic_block:
            self.closed_in_transaction = True
            self.needs_rollback = True
        else:
            self.connection = None
