[ZODB-Dev] Closing ZODB connection

Dieter Maurer dieter at handshake.de
Fri Oct 31 16:51:57 EST 2003


Antonio Beamud Montero wrote at 2003-10-31 10:57 +0100:
 > I have find the problem. As Dieter said, was a problem in my app. A
 > method open a connection and with the open connection this method calls
 > other method that open other connection, but when this second method try
 > to do a commit it hang up. Whit several threads all the server hang up.
 > Now I do the following:
 >   
 >    method_A()
 >      con = self.db.open()
 >      ...<process>
 >      con.close()                         method_B()
 >      x = self.method_B()    ----------->    con = self.db.open()
 >      con = self.db.open()                   ...<process>
 >      ...<process>                           con.close()
 >      con.close()
 > 
 > Is the correct approach or is better only open in A and close when exit
 > A? i.e. something like:
 >    method_A()
 >       con = self.db.open()
 >       ...<process>                         method_B()
 >       x = self.method_B() ---------------      ...<process>
 >       ...<process>
 >       con.close()  

When "A" and "B" run in the same thread, then the second approach
is better (as you save one precious connection).

When "A" and "B" can run in different threads, you will need
the first approach. In general, it is unsafe to pass persistent
objects and connections between threads.

-- 
Dieter



More information about the ZODB-Dev mailing list