[Twisted-Python] laxdb - an async dbapi wrapper

Vishal Shetye vishalshetye at gmail.com
Thu Jul 23 11:39:53 EDT 2009

> Hi,
> In response to the announcement of the Twisted Asynchronous Database Api
> (tada), <http://www.darkarts.co.za/projects/tada/, I thought I should
> mention something I wrote.
> [Unfortunately, tada does not use threads correctly so it's likely to
> break. The author knows this and has added a warning to the module for
> A while back, I started messing around with making a standard, blocking
> db-api module appear non-blocking but with a deferred API. I called it
> laxdb and it's in my sandbox.
>     svn://svn.twistedmatrix.com/svn/Twisted/sandbox/mg/laxdb.py
>     http://svn.twistedmatrix.com/cvs/sandbox/mg/laxdb.py?view=markup
> laxdb is quite literally an async db-api interface and not a
> t.enterprise.adbapi style interface. In particular, it provides exactly
> the same API (but deferred) and it doesn't take over transaction
> management. It also doesn't wrongly call a cursor, "Transaction" ;-).
> I recently went back to laxdb and finished it off, also adding a
> connection pool implementation.
> Now, I haven't used laxdb in a real project and there are no unit tests
> but I think it's reasonably complete. It should work with any dbapi
> module that has threadsafety level 1 or higher, just like adbapi.
> If there's interest in this way of accessing a database then I would be
> happy to write tests etc, move it into Twisted and maintain it.
> Cheers, Matt

I guess there have not been any additions to this module in recent time.
I just tried to use it, sample code, actually a failure test, is as below
which does not actually do any query. Reactor is stopped without commit or
This raises an exception in removeTrigger_BASE.
    exceptions.ValueError: list.remove(x): x not in list

I could fix it, in class WorkerThread, function _start has line
    self._shutdownTriggerId = reactor.addSystemEventTrigger('after',
'shutdown', self.shutdown)

self.shutdown is called by Connection.close() or reactor.stop(). In case of
second, reactor.stop, registered function, self.shutdown in this case,
should not do

However, this raises some doubts about overall code as there are no test
cases to prove the correctness.
Has anyone used this before? Can somebody provide pointers on what
scenarios/conditions should be tested?
laxdb is good match for what I want, interleaved calls and async interface
to db. Is there any alternative available?

from laxdb import ConnectionPool
from twisted.internet import reactor

pool = ConnectionPool("sqlite3", database='laxdbTest', timeout=5.0,

def connect(pool):
    d = pool.connect()

def connected(conn):
    curs = conn.cursor()

reactor.callWhenRunning(connect, pool)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20090723/7844f470/attachment.htm 

More information about the Twisted-Python mailing list