[ZODB-Dev] question about connections

Victor Safronovich vsafronovich at naumen.ru
Fri Oct 21 04:54:58 EDT 2005


Hello zodb-dev!

I have Zope 2.6.1 with ZODB 3.1.5 ( I know this is old versions ).

I have scheduler in separate thread with code

class EventDispatcher( threading.Thread ):
    running = False
    def __init__( self, scheduler ):
        self.scheduler_path = scheduler.getPhysicalPath()
        threading.Thread.__init__( self, name='Scheduler_%s' % scheduler.getSchedulerName() )

    def run( self ):
        """
            Start as main schedule thread.
        """
        LOG( Config.ProductName,
             TRACE,
             'Started dispatcher thread for scheduler %s' % '/'.join( self.scheduler_path ),
           )

        app = Zope.bobo_application()
        try:
            self.running = True
            while self.running:
                get_transaction().begin()
                try:
                    scheduler = app.unrestrictedTraverse( self.scheduler_path )
                    scheduler.dispatchEvents()
                    get_transaction().commit()
                except Exception:
                    get_transaction().abort()
                threading.Event().wait( random() )
        finally:
            app._p_jar.close()

            LOG( Config.ProductName,
                 TRACE,
                 'Terminating dispatcher thread for scheduler %s' % '/'.join( self.scheduler_path ),
                )

    def terminate( self ):
        self.running = False
        threading.Event().wait( random() )
        
But connection to the ZODB in the app object some times does`t see modifications
from the others connections :(.

This repaired in this way
    def run( self ):
        """
            Start as main schedule thread.
        """
        LOG( Config.ProductName,
             TRACE,
             'Started dispatcher thread for scheduler %s' % '/'.join( self.scheduler_path ),
           )

        self.running = True
        while self.running:
            app = Zope.bobo_application()
            try:
                get_transaction().begin()
                try:
                    scheduler = app.unrestrictedTraverse( self.scheduler_path )
                    scheduler.dispatchEvents()
                    get_transaction().commit()
                except Exception:
                    get_transaction().abort()
                threading.Event().wait( random() )
            finally:
                app._p_jar.close()

        LOG( Config.ProductName,
              TRACE,
              'Terminating dispatcher thread for scheduler %s' % '/'.join( self.scheduler_path ),
            )
            
But  this  create  new  ZODB-connection every time, is this bad or good? And Why
one   connection   in   the   first   example   not  see  modifications from the
other connections? Is this a ZODB 3.1.5 problem or my?

-- 
Best regards,
 Victor Safronovich
 NauMen.NauDoc.SoftwareDeveloper  http://www.naumen.ru



More information about the ZODB-Dev mailing list