[ZODB-Dev] Opening 7 Connections hangs (and __del__)

Christian Reis kiko@async.com.br
Fri, 31 Jan 2003 19:40:21 -0200


On Fri, Jan 31, 2003 at 04:04:17PM -0500, Jeremy Hylton wrote:
> Right on both points.
> 
>   CR> It's trivial to have a wrapper around connection that takes care
>   CR> of this, calling conn.close() on __del__ and incrementing the
>   CR> pool size when another simultaneous connection is required.
> 
> An __del__ method isn't going to work, because the database always has
> a reference to the connection.  It's not going to be collected until
> the database is closed and the thread releases its reference.  The
> database must have a reference to the connection, otherwise it would
> be unable to reuse it.

I tricked you <wink>. I didn't suggest a __del__ method on the
Connection class, but on the "wrapper around connection". Something like
this:

# db points to a DB instance
def create_connection():
    return Connection(db)

def Connection:
    def __init__(self, db):
        self._conn = db.open()

    def __del__(self):
        self._conn.close()

    def abort(self):
        return self._conn.abort()

    def commit(self):
        return self._conn.commit()

    def root(self):
        return self._conn.root()

    def get_catalog(self, name):
        # Implement IndexedCatalog related catalog puller
        pass

You could of course decorate Connection with a few more "interesting"
methods of connection that you want. But it does simplify things if you
don't want to force all callers to necessarily clean up completely after
closing up (since one might normally assume the connection was destroyed
upon being released).

Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL