> Hi,<br>><br>> In response to the announcement of the Twisted Asynchronous Database Api<br>> (tada), <<a href="http://www.darkarts.co.za/projects/tada/">http://www.darkarts.co.za/projects/tada/</a>, I thought I should<br>
> mention something I wrote.<br>><br>> [Unfortunately, tada does not use threads correctly so it's likely to<br>> break. The author knows this and has added a warning to the module for now.]<br>><br>> A while back, I started messing around with making a standard, blocking<br>
> db-api module appear non-blocking but with a deferred API. I called it<br>> laxdb and it's in my sandbox.<br>><br>> svn://<a href="http://svn.twistedmatrix.com/svn/Twisted/sandbox/mg/laxdb.py">svn.twistedmatrix.com/svn/Twisted/sandbox/mg/laxdb.py</a><br>
> <a href="http://svn.twistedmatrix.com/cvs/sandbox/mg/laxdb.py?view=markup">http://svn.twistedmatrix.com/cvs/sandbox/mg/laxdb.py?view=markup</a><br>><br>> laxdb is quite literally an async db-api interface and not a<br>
> t.enterprise.adbapi style interface. In particular, it provides exactly<br>> the same API (but deferred) and it doesn't take over transaction<br>> management. It also doesn't wrongly call a cursor, "Transaction" ;-).<br>
><br>> I recently went back to laxdb and finished it off, also adding a<br>> connection pool implementation.<br>><br>> Now, I haven't used laxdb in a real project and there are no unit tests<br>> but I think it's reasonably complete. It should work with any dbapi<br>
> module that has threadsafety level 1 or higher, just like adbapi.<br>><br>> If there's interest in this way of accessing a database then I would be<br>> happy to write tests etc, move it into Twisted and maintain it.<br>
><br>> Cheers, Matt<br><br>I guess there have not been any additions to this module in recent time.<br>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 rollback. <br>
This raises an exception in removeTrigger_BASE.<br> exceptions.ValueError: list.remove(x): x not in list<br><br>I could fix it, in class WorkerThread, function _start has line<br> self._shutdownTriggerId = reactor.addSystemEventTrigger('after', 'shutdown', self.shutdown)<br>
<br>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 <br> reactor.removeSystemEventTrigger(self._shutdownTriggerId) <br>
<br>However, this raises some doubts about overall code as there are no test cases to prove the correctness.<br>Has anyone used this before? Can somebody provide pointers on what scenarios/conditions should be tested?<br>
laxdb is good match for what I want, interleaved calls and async interface to db. Is there any alternative available?<br><br>[code]<br>from laxdb import ConnectionPool<br>from twisted.internet import reactor<br><br>pool = ConnectionPool("sqlite3", database='laxdbTest', timeout=5.0, check_same_thread=False)<br>
<br>def connect(pool):<br> d = pool.connect()<br> d.addCallback(connected)<br><br>def connected(conn):<br> curs = conn.cursor()<br> reactor.stop()<br><br>reactor.callWhenRunning(connect, pool)<br>reactor.run()<br>
[/code]<br><br>Regards,<br>vishal<br>