[Twisted-Python] adbapi question
Hello. from twisted.enterprise import adbapi from twisted.internet import reactor from twisted.spread import pb DB_HOST = "localhost" DB_USER = "root" DB_PASSWD = "xxx" DB_NAME = "account" class DBException(pb.Error): pass dbpool = adbapi.ConnectionPool("MySQLdb", host=DB_HOST, user=DB_USER, passwd=DB_PASSWD, db=DB_NAME) # Database checking def getClientsDBParams(username): _sql = """ SELECT username, password, ip, netmask, mac FROM bunkernet_clients WHERE username='%s' """ % username return dbpool.runQuery(_sql) def dbClientSucceeded(self, l): if l: print l else: print "no records" raise DBException("No records") def dbClientFailed(): print "Failed!" reactor.stop() getClientsDBParams('alienoid').addCallbacks(dbClientSucceeded, dbClientFailed) reactor.run() The problem here is that when dbClientSucceeded is executed and i get "no records" - i don't get exception. Only when i press Ctrl + C on server i get those DBException. This code will be executed when remote client connects to server and i want those DBException be passed to remote client but i can't get it, can get it only with Ctrl + C Your help is very appreciated. Thanks in advance. Best regards, Ruslan
On Fri, Sep 26, 2003 at 05:08:58PM +0300, Ruslan Spivak wrote:
[snip]
def dbClientFailed(): print "Failed!" reactor.stop()
getClientsDBParams('alienoid').addCallbacks(dbClientSucceeded, dbClientFailed) reactor.run()
The problem here is that when dbClientSucceeded is executed and i get "no records" - i don't get exception. Only when i press Ctrl + C on server i get those DBException. This code will be executed when remote client connects to server and i want those DBException be passed to remote client but i can't get it, can get it only with Ctrl + C
Your help is very appreciated. Thanks in advance.
Errbacks receive a single argument, the failure that caused them to be caused. Unfortunately, if you define your errback to take no arguments (as you have), that error becomes a failure, which would pass on to the next errback if it were registered, or, as in your code, would be silenced if there are no more errbacks. Redefine dbClientFailed to take an argument and you should see the behavior you expect. Jp
participants (2)
-
Jp Calderone
-
Ruslan Spivak