Hi all

I am a new user to the Twisted framework so this might be a trivial question, but here goes..

Im trying to use the Web module and adbapi module to create a (rest) webservice but I am having problems using the adbapi. As fare as I could figure out, the runInteraction call spawns a new thread and executes the sql in that, and the render_GET handler is then returning right away -bummer. I need the adbapi for its db pool but dont need it to be "blocking" so that I can return the result of the db interaction as xml.

Hope you guys can help me out or give me some pointers if I am doing this the wrong way.


Regards
  Søren

----- Code ----
from twisted.web import server
from twisted.internet import reactor
from twisted.enterprise import adbapi
from xml.dom.minidom import Document

class Simple(Resource):
    isLeaf=True
    def __init__(self,opt):
        Resource.__init__(self)
        self.opt=opt

    def render_GET(self,request):
        doc=Document()
        self.opt.dbpool.runInteraction(self._getUserList,doc)
        print "returning result"
        return doc.toprettyxml(indent="  ")

    def _getUserList(self,txn,doc):
        txn.execute("SELECT UserName FROM User ")
        res = txn.fetchall()
        if (res):
            for row in res:
                print row
                usr=doc.createElement("user")
                usr.setAttribute("name","%s" % (row[0] ))

class options:
    pass

if __name__ == '__main__':
options.dbpool= adbapi.ConnectionPool("MySQLdb", host='localhost',db='TrackingPresentation',
                                   user='web', passwd='tingogsager')
    site = server.Site(Simple(options))
    reactor.listenTCP(8888,site)
    reactor.run()

------ Code ------



_______________________________________________
Twisted-web mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

Reply via email to