[Twisted-web] database best practices
Drew Perttula
drewp at bigasterisk.com
Sat Nov 29 17:00:23 EST 2008
Martin Bright wrote:
>
> What is the best way to implement synchronous DB access in a twisted
> application? I've read about defer.deferredGenerator, and various
> threads about how it's a stupid idea to even attempt this. Do I have
> restructure my code such that everything that depends on results from
> a database query is in a callback to a deferred object?
>
I'm using deferredGenerator (and the yummier inlineCallbacks) all over
with my database calls. My database is an RDF database that I talk to
over HTTP (with my http://projects.bigasterisk.com/sparqlhttp/). The
inlineCallbacks API is so great, you won't miss synchronous code at all.
My setup doesn't have transactions, which is one issue with twisted db
access. I try to arrange my updates so only the last atomic piece
matters. If something goes wrong, my worst case should be some orphaned
data. Ebay might work like this too:
http://martinfowler.com/bliki/Transactionless.html
More information about the Twisted-web
mailing list