[Twisted-Python] twisted.enterprise / transactions
![](https://secure.gravatar.com/avatar/b932b1e5a3e8299878e579f51f49b84a.jpg?s=120&d=mm&r=g)
I've been looking into twisted.enterprise.. and I have a few questions 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. Similarly, what's the point of rolling back on error if you can't use transactions anyways? If it errored, it didn't do anything anyways. One more thing, do you need to do anything with threadable before using enterprise? -bob
![](https://secure.gravatar.com/avatar/433365de0f787faa3ed3e6dd1da5884f.jpg?s=120&d=mm&r=g)
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()).
![](https://secure.gravatar.com/avatar/588326b78898c23564d107c4fa70c2f0.jpg?s=120&d=mm&r=g)
right. take a look at twisted.forum.manager.py postMessage() and _messagePoster() for an example. -----Original Message----- From: twisted-python-admin@twistedmatrix.com [mailto:twisted-python-admin@twistedmatrix.com]On Behalf Of Itamar Shtull-Trauring Sent: Monday, February 11, 2002 11:28 AM To: twisted-python@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@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
participants (3)
-
Bob Ippolito
-
Itamar Shtull-Trauring
-
Sean Riley