[Twisted-Python] adbapi question
Ruslan Spivak
alienoid at is.lg.ua
Fri Sep 26 08:08:58 MDT 2003
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
More information about the Twisted-Python
mailing list