[ZODB-Dev] Closing ZODB connection
Antonio Beamud Montero
antonio.beamud at linkend.com
Thu Oct 30 10:26:10 EST 2003
I have increased de connection pool and works until reaches the
connections limit.
I close a connection when it has terminated, but it seems not closed.
I'm very confused with DB, connection and root...
If I close a connection, why I can use the root object?
I don't understand anything... :-(
El jue, 30-10-2003 a las 16:16, Antonio Beamud Montero escribió:
> When multiple threads are working I have problem to close connections
> and the server hangup...
>
> I have seen that you treated this problem (closing connections). Can be
> valid for my problem something like Christian proposed in a mail to the
> list in Fri, 31 Jan 2003.
> ----- Mail list ------------------
> ....
> 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).
>
> When the method exist, the connection object is automatically destroyed and the __del__ method is executed...
>
> Thanks
>
>
>
> El mié, 29-10-2003 a las 17:41, Jeremy Hylton escribió:
> > On Wed, 2003-10-29 at 11:25, Antonio Beamud Montero wrote:
> > > El mié, 29-10-2003 a las 17:17, Jeremy Hylton escribió:
> > > > On Wed, 2003-10-29 at 11:05, Antonio Beamud Montero wrote:
> > > > > Then in a case as before I need to do something like:
> > > > > def get_reg_list(self):
> > > > > con = self.db.open()
> > > > > root = con.root()
> > > > > list = root['status'].get_register_list()
> > > > > con.close()
> > > > > return list
> > > > >
> > > > > No?
> > > >
> > > > No. You need to keep the connection open as long as you are using
> > > > objects that were loaded from that connection. The list you are
> > > > returning contains objects loaded from con, so you can't close it.
> > >
> > > What? This method is called like a SOAP method within an http server.
> > > How I can do the things rigth?
> > > Making a newlist = copy.copy(list)?
> >
> > Let's take a step back and help me figure out what you are trying to
> > accomplish.
> >
> > You use a database connection to load objects from the database. When
> > you load the status object from the root, you are loading a surrogate
> > for the real object in the database. The object's state isn't loaded
> > until you access the object. The same is true for any attribute of
> > status that inherits from Persistent. In general, objects are only
> > loaded when you use them and the cache is free to release the state of
> > objects that are reachable but not currently being used.
> >
> > The database connection is used to load objects, so you can't safely
> > close while you are using objects loaded from the database. A typical
> > program opens a database connection when it starts and closes it when it
> > exits. In Zope, each request uses a separate database connection, and
> > database content is never used except in the context of a request.
> >
> > Jeremy
--
Antonio Beamud Montero <antonio.beamud at linkend.com>
More information about the ZODB-Dev
mailing list