[Zope] Zope Freezing up with multiple threads accessing objects.

Etienne Labuschagne elabuschagne@gmsonline.co.za
Mon, 14 Jul 2003 02:53:48 +0200


Hi all,

I need to access Zope object in the ZODB from multiple threads every now 
and again (much like XRON does - except I have more threads that need to 
access it).  Now I know I must get a valid connection into the ZODB every 
time a new thread wakes up and wants to get something done.  I do this by 
getting a connection from the ZODB.DB instance in Globals and then getting 
the Application object from there.

Unfortunately I am plagued by sporadic Zope freezing, where Zope accepts 
connections from a browser, but the page never returns (needless to say, 
all new threads that wake up and try and get the app also freezes).

No crashes, exceptions, etc.  After some very sophisticated print debugging 
;) I have traced the problem to the ZODB.DB's "global" lock, ZODB.DB.l, not 
being released after DB.begin_invalidation has been called by 
ZODB.Connection.tpc_finish which has been called by 
ZODB.Transaction._finish_many which has been called by 
Transaction.commit.  It seems as if ZODB.DB.finish_invalidation has never 
been called to release the lock after the initial begin_invalidation called 
by tpc_finish.

It seems to me that this whole sequence is triggered by 
get_transaction().commit(), but I can't quite figure out what I am doing 
wrong.

I get this problem on Zope 2.6.1 on both Win2k and Linux (four different 
machines), and yes, I did register my thread with ThreadedAsync to start my 
thread up.  That thread, however starts up other threads - do I need to 
register those threads with ThreadedAsync too?

FYI I get the App object as follows - is this the best way?  If I get a 
temporary connection, do I also need to call close?:

import Globals
connection = Globals.DB.open(temporary=1) #I have also tried getting from 
the pool with no params, and with force=1
app = connection.root()['Application']
# some code using the app object here
get_transaction().commit()
app._p_jar.close()

I have also tried using ZApplication.ZApplicationWrapper, etc, etc.

Zope will run for hours before freezing or will freeze after about 10 
seconds - totally random - what am I doing wrong?

Thanks
Etienne