[ZODB-Dev] Closing ZODB connection

Jeremy Hylton jeremy at zope.com
Wed Oct 29 11:41:40 EST 2003


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





More information about the ZODB-Dev mailing list