Re: [Twisted-Python] adbapi results through xmlrpc
Returning a deferred from the xmlrpc method will work fine -- twisted will use the result of the deferred and not the deferred itself when sending the return xml-rpc value. The problem is that the result of the query is not serializable, probably because it contains some pgsql objects somewhere. Instead of sending the result directly, you'll probably want to add a callback that picks the count value out of the row and column. Also, the type of the count may not be a regular integer but some pgsql-specific type. You'll have to do some debugging to see what's going on. Also, you probably don't want to create a connection pool for every call, but if you do, don't forget to close the pool or you may end up with lots of open connections. dave ---- Original Message ---- From: Zach Thompson Date: Wed 3/31/04 13:22 To: twisted-python@twistedmatrix.com Subject: [Twisted-Python] adbapi results through xmlrpc Hello, I'm trying to connect 2 scripts (a server and client) xmlrpc. The server just needs to run a db query and return the result set to the client for display. Here's part of the server class: def xmlrpc_get_count(self): from twisted.enterprise import adbapi pool = adbapi.ConnectionPool("pyPgSQL.PgSQL", database="zach") return pool.runQuery("select count(*) from asdf") And part of the client class: def OnButton(self, event): from twisted.web.xmlrpc import Proxy proxy = Proxy("http://localhost:8080") proxy.callRemote('get_count').addCallback(self.UpdateCount) def UpdateCount(self, count): self.label.SetLabel(count) Here's what the client prints when I press the button: Unhandled error in Deferred: Failure: xmlrpclib.Fault: <Fault 8002: "can't serialize output"> I can understand that xmlrpc needs to serialize the Deferred object to send it through http. I'm guessing there's a reference to the ConnectionPool object contained in the Deferred, and it makes sense that you wouldn't be able to serialize something like that. Any ideas? BTW, the client is running on a wxreactor, if that matters.. Thanks, Zach
participants (1)
-
dave@krondo.com