[ZODB-Dev] question about connections

Dieter Maurer dieter at handshake.de
Fri Oct 21 14:33:24 EDT 2005


Victor Safronovich wrote at 2005-10-21 14:54 +0600:
> ...
>        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()
> ...
>But connection to the ZODB in the app object some times does`t see modifications
>from the others connections :(.

This is not surprising:

  The world changes for a single thread only at (its) transaction boundaries.

  Changes committed by other threads after the "commit/abort" above
  are not seen in this thread until it executed a new "commit/abort".

  Thus, in case "dispatchEvents" blocks for events, you may loose
  modifications.

>This repaired in this way
> ...
>            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()

Now, you will loose only those modifications happening after
the "app = ...".
You reduced the risk but can not yet be sure...

> ...
>But  this  create  new  ZODB-connection every time, is this bad or good?

A single one would be a bit more efficient -- but you need not to care.

-- 
Dieter


More information about the ZODB-Dev mailing list