[Twisted-Python] twisted.enterprise / transactions

Sean Riley sean at twistedmatrix.com
Mon Feb 11 20:13:24 MST 2002


right. take a look at twisted.forum.manager.py postMessage() and
_messagePoster() for an example.

-----Original Message-----
From: twisted-python-admin at twistedmatrix.com
[mailto:twisted-python-admin at twistedmatrix.com]On Behalf Of Itamar
Shtull-Trauring
Sent: Monday, February 11, 2002 11:28 AM
To: twisted-python at twistedmatrix.com
Subject: Re: [Twisted-Python] twisted.enterprise / transactions


Bob Ippolito wrote:

> It seems that enterprise expects that you want to commit data for every
> successful query?  This certainly makes things simpler, as with
> PostgreSQL a separate backend (connection) is going to be running for
> every connection to that database, which means the thread pool would
> require some more complicated management.  There ought to be a way to
> set it up such that your callbacks can do more processing and guarantee
> that it happens in the same thread, so you get the same connection, and
> don't have to commit every time.  Committing after every query kinda
> defeats the purpose of having transactions at all, unless you do
> everything in user defined functions (stored procedures) that use
> transactions themselves.


There is support for doing so.


Specifically, adabpi.ConnectionPool.interaction() lets you pass a
callable object  (a function or method). The method you pass will be
called with an instance of adabpi.Transaction, upon which you can run a
series of SQL commands, after which the changes will be commited
automatically (or rollbacked if there's an exception thrown.)

So, write a function that accepts one argument, an instance of
adbapi.Transaction, and does a series of SQL commands on this instance.
Then, pass this function to your connectionpoool's interaction() method.


> One more thing, do you need to do anything with threadable before using
> enterprise?

Nope, it will automatically do that for you, on the assumption
enterprise.adbapi is imported before your program starts, i.e. before
you call your Application's run() method (or t.i.main.run()).


_______________________________________________
Twisted-Python mailing list
Twisted-Python at twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python





More information about the Twisted-Python mailing list