Interception de ConnectionStateError qui peut survenir lorsque des images sont suppri...
[Portfolio.git] / manipulation.py
index 9f65866..dcba20d 100755 (executable)
@@ -18,6 +18,8 @@ from types import StringTypes
 from math import ceil
 import transaction
 from ZODB.POSException import ConflictError
+from ZODB.POSException import ConnectionStateError
+from zope.site.hooks import setSite
 from cStringIO import StringIO
 
 console = logging.getLogger('[manipulation thread]')
@@ -50,15 +52,17 @@ class ImageQueueProcessorThread(threading.Thread) :
                #atexit.register(self.stop)
                import Zope2
                app = Zope2.app()
+               portal = app.unrestrictedTraverse(self.portal_path)
+               setSite(portal)
                while not self.__stopped and self.queueSize :
                        self._process(app)
                
                con = app._p_jar
-               con.close()
-               #con.close()
+               try :
+                       con.close()
+               except ConnectionStateError, e :
+                       console.warn('ConnectionStateError raised before finished.')
                console.info('process finished.')
-               #print con
-               #print con.transaction_manager
                
 
        def stop(self):
@@ -122,6 +126,7 @@ class ImageQueueProcessorThread(threading.Thread) :
                                pass
                        
                        p.tiles_available = 1
+                       assert p._getCatalogTool()
                        p.reindexObject(idxs=['tiles_available'])
                        transaction.commit()