[ZODB-Dev] Deferred notifing from one thread to another.

Victor Safronovich vsafronovich at naumen.ru
Fri Dec 9 04:33:55 EST 2005


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



More information about the ZODB-Dev mailing list