On Thu, Jan 26, 2006 at 01:35:56PM +0100, Andreas Kostyrka wrote: > Any chance to see this extra code to handle transactions or at least > pseudo code?
I'll repeat all the code here again then:
def makeTransactWith(engine):
def acquire(*a):
def transactor(f):
def _(*args, **kwargs):
if a:
# What an HACK!!!
self = args[0]
# These MUST be immutables currently to avoid
# deadlocks/races
ca = tuple(getattr(self, el, None) for el in a)
args = (self,)+ca+args[1:]
def _1():
engine.begin()
try:
r = f(*args, **kwargs)
except:
engine.rollback()
raise
else:
engine.commit()
return r
return threads.deferToThread(_1)
_.__name__ = f.__name__
return _
return transactor
return acquire
transact = makeTransactWith(engine)()
transactWith = makeTransactWith(engine)
> I haven't yet tried, but I think the following should work:
>
> deferToThread
> create a Thread context in the Uow engine
> fetch all objects.
> main thread:
> restore the Thread context for the uow engine and
> work with the objects
> deferToThread
> restore the Thread context for the uow engine
> objectstore.commit()
I don't use the mapper. But I would like if it kept the change information in
one place rather than in a thread, so that it can be used with a threadpool
with the commits() sent from a different thread, otherwise that would break
the logic pretty much. By the way I'm not integrating the mapper yet I just
like SQL but I find it boring to type that's why I like the sql construction
library inside SQLAlchemy and I work to use that :).
--
Valentino Volonghi aka Dialtone
Now Running MacOSX 10.4
Blog: http://vvolonghi.blogspot.com
New Pet: http://www.stiq.it
pgpeccyrTiwK3.pgp
Description: PGP signature

