Hello zodb-dev!

I have a some problem, and don`t know how to solve it :(.

I have a scheduler dispatcher thread with run method

def run(self):
        app = Zope2.bobo_application()
        try:
            scheduler = app.unrestrictedTraverse( self.scheduler_path, None )
            queue = scheduler.getEventQueue( reset=True )

            while not DieEvent.isSet():
                    if ResetEvent.isSet():
                        ResetEvent.clear()
                        app._p_jar.sync()
                        # refresh the queue and set new expires time
                        queue.refresh()

                    event = queue.getNextEvent()
                    if event and event.waitTillStart( ResetEvent ):
                        EventSemaphore.acquire()
                        event.setDaemon(True)
                        event.setSemaphore( EventSemaphore )
                        event.start()

                    elif not ResetEvent.isSet():
                        # No events left in the queue.
                        # Just waiting for the queue to expire.
                        delay = queue.expires - now()
                        ResetEvent.wait( delay.seconds )
                        ResetEvent.set()

        finally:
            app._p_jar.close()

and a Scheduler class with addScheduleElement method

class Scheduler(BTreeFolder2):

    def addScheduleElement(self, **options):
        self._setObject(self.generateId(), ScheduleElement(**options))
        ResetEvent.set()
        
addScheduleElement  is  called  from ZServer thread.
for instance dispather thread is 'T1', and ZServer thread is 'T2'.

addScheduleElement  sets  ResetEvent  and dispatcher refreshed queue, dispatcher
called  app._p_jar.sync()  to  see modifications from other threads. But when T2
still not commiting its transaction, dispatcher not see new element :(.

I thinks if there is an afterCommitHook at transaction, i`ll use it, but it is 
not exist.

Of course i may write time.sleep( SLEEP_CONSTANT ) before app._p_jar.sync(), but
is this a good solution?

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

_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev

Reply via email to