[ZODB-Dev] BTreeFolder2 causes "RuntimeError: Shouldn't load state for"?

Dieter Maurer dieter at handshake.de
Thu Jul 22 15:32:22 EDT 2004


Syver Enstad wrote at 2004-7-22 10:25 +0200:
>Dieter Maurer <dieter at handshake.de> writes:
>
>> Persistent objects must never:
>> 
>> 
>>   *  not be passed between threads
>
>Is it okay to just read persistent objects after a thread has modified
>them?

Usually not...

There are three problems:

 1. different threads may develop independently and the
    thread that opened the ZODB connection may choose
    to close it (usually a good idea!).
    When the second thread needs the ZODB connection in order
    to fetch data from the ZODB, it will get a
    "Should load objects while the connection is closed" exception.

 2. The ZODB is designed to not share connections between threads.
    Therefore, it does not protect modification of connection
    related data (e.g. its cache) by locks.
    Race conditions may result when a connection is shared
    between threads (even when they only read as reading objects
    causes writing of cache entries).

 3. The standard ZODB transaction model is one transaction
    per thread. If persistent objects in one connection
    are modified in different threads the modifications
    effectively are associated with different transactions.

    Very funny behaviour may result -- as you can find out
    when you search the mailing list archive...

-- 
Dieter


More information about the ZODB-Dev mailing list