[Zope-DB] zope threading issue

Dieter Maurer dieter@handshake.de
Sat, 8 Feb 2003 11:52:34 +0100

sameer chaudhry wrote at 2003-2-5 08:34 -0500:
 > Basically, I have a product that starts of a new thread in the init method which performs a long computation and when it's done it updates a value in the main thread.  The thread is supposed to run forever as it's in a while loop that sleeps and runs the computation, yet the computation is only performed once.

You should (must) read the ZODB3 documentation and learn how the ZODB works:

  Persistent objects have an implicite reference ("_p_jar") to
  a ZODB connection. Through this connection they
  read in more objects on demand and they write changes back to ZODB.

  In Zope, the connection is closed when the request ends.

  When you pass a persistent object to a separate thread,
  your thread's lifetime is independent from the current request.
  It may use a stale ZODB connection (with weird consequences).

  You see a somewhat harmless case:

    Almost surely, changing the state results in an exception
    which ends your loop.

  To fix this, your thread must open its own ZODB connection
  and take over transaction management (normally done by

As said, read the ZODB3 documentation...