Deprecation problem and ConnectionStateError, was: Re: [ZODB-Dev] Span transaction over several threads

Tim Peters tim at zope.com
Thu Sep 9 18:48:32 EDT 2004


[Diez Roggisch]
> ...
> If I understood the NEWS.txt correctly, the other TM that I use will
> instead of associating the sync-stuff thread-local associate it globally
> to all threads.  But I fear that this could cause trouble, depending on
> how that is accomplished - on a per-connection-base for all threads, or
> for all connections for all threads.

The intent is that you pass a distinct transaction.TransactionManager
instance to each DB.open() call.  The easiest way to do that is probably to
create a new TransactionManager instance each time you do DB.open(), but
nobody ever settles for obvious strategies <wink>.  If TM1 and TM2 are
distinct TransactionManager instances, TM1.get() and TM2.get() will retrieve
distinct Transaction objects.  So if you pass distinct TM1 and TM2 to two
different DB.open() calls, the two resulting connections will each have
their own unique TransactionManager, each managing its own, unique, single
Transaction instance.

Threads are just irrelevant here -- threads have nothing to do with it.
That's the *point* of transaction.TransactionManager (and was also the point
of setLocalTransaction).  If 500 threads all call ATransactionManager.get()
at the same time, they'll all get the same Transaction object back.  In
exactly the same way, if 500 threads all called AConnection.getTransaction()
at the same time, after one thread did AConnection.setLocalTransaction(),
they too would all get the same Transaction object back.

Of course if you pass the *same* TransactionManager instance to each
DB.open() call, then that instance will be shared across all the Connections
created, and then all the Connections will share a single Transaction object
too.  That would be insane, perhaps exactly in the way you fear, so don't do
that.

...
> But the problem has been solved - I accidentially introduced an error in
> the setUp method, and that caused an assertion in there to fail.

Ah!  Don't do that either <wink>.



More information about the ZODB-Dev mailing list