[Zope-Checkins] CVS: Zope/lib/python/Products/ZCatalog/regressiontests - loadmail.py:1.8

Barry Warsaw barry@wooz.org
Thu, 22 Aug 2002 17:43:18 -0400


Update of /cvs-repository/Zope/lib/python/Products/ZCatalog/regressiontests
In directory cvs.zope.org:/tmp/cvs-serv13359/lib/python/Products/ZCatalog/regressiontests

Modified Files:
	loadmail.py 
Log Message:
do(): We need to wrap the guts of this in a try/finally so that the
returnf() function will definitely get called.  Otherwise, if we get
an exception during the test, we'll deadlock because it's returnf()
that releases the various test locks.

loadinc(): Pass the file pointer in as well as the mbox so that the
status printing will actually work.  I'm not passing the file in
/instead/ of the mbox, but I wasn't completely sure of the original
intent of the code.


=== Zope/lib/python/Products/ZCatalog/regressiontests/loadmail.py 1.7 => 1.8 ===
--- Zope/lib/python/Products/ZCatalog/regressiontests/loadmail.py:1.7	Wed Aug 14 18:25:16 2002
+++ Zope/lib/python/Products/ZCatalog/regressiontests/loadmail.py	Thu Aug 22 17:43:17 2002
@@ -117,17 +117,22 @@
 
 def do(db, f, args, returnf=None):
     """Do something and measure it's impact"""
-    size=db.getSize()
-    mem=VmSize()
-    t=time.time()
-    c=time.clock()
-    r=apply(f, args)
-    t=time.time() - t
-    c=time.clock() - c
-    size=db.getSize()-size
-    mem=VmSize()-mem
-    if returnf is not None: returnf(t, c, size, mem, r)
-    else: return t, c, size, mem, r
+    t = c = size = mem = r = None
+    try:
+        size=db.getSize()
+        mem=VmSize()
+        t=time.time()
+        c=time.clock()
+        r=apply(f, args)
+        t=time.time() - t
+        c=time.clock() - c
+        size=db.getSize()-size
+        mem=VmSize()-mem
+    finally:
+        if returnf is not None:
+            returnf(t, c, size, mem, r)
+        else:
+            return t, c, size, mem, r
 
 def loadmessage(dest, message, i, body=None, headers=None):
     if body is None: body=message.fp.read()
@@ -189,7 +194,7 @@
     print
     get_transaction().commit()
 
-def loadinc(name, mb, printstat=0, max=99999999, wait=1):
+def loadinc(name, mb, f, printstat=0, max=99999999, wait=1):
     from ZODB.POSException import ConflictError
     from time import sleep
     from whrandom import uniform
@@ -351,7 +356,8 @@
         amin=min+i*count
         dest='maili%s' % amin
         initmaili(dest)
-        mb=mailbox.UnixMailbox(open(mbox))
+        f = open(mbox)
+        mb=mailbox.UnixMailbox(f)
         j=0
         while j < amin:
             mb.next()
@@ -361,7 +367,7 @@
         def returnf(t, c, size, mem, r, lock=lock):
             print c, r
             lock.release()
-        argss.append((lock, (dest, mb, 0, count, wait), returnf))
+        argss.append((lock, (dest, mb, f, 1, count, wait), returnf))
 
     for lock, args, returnf in argss:
         thread.start_new_thread(do, (Zope.DB, loadinc, args, returnf))