[Twisted-Python] adbapi question

Jon Dyte jon at totient.demon.co.uk
Wed Apr 30 18:28:31 EDT 2003


Hi

Below is a small script. My question is what is the correct way to exit after using the adbapi stuff. The script as it stands just hangs the terminal
until I Ctrl-Z and kill it.
sample run

jon> python simpledb.py jon jon jon
Done
0
finished
{1026: <connection object at 0x8228048>}
0
[<_MainThread(MainThread, started)>, <Thread(PoolThread-136416140-1, started)>]


Jon


import sys
import threading
import pprint
from twisted.enterprise import adbapi
from twisted.internet import reactor

dbname,user,passwd = sys.argv[1:4]

class SomeTable(adbapi.Augmentation):
    def getSomeData(self):
        self.done = 1
        qry = "select * from SomeTable"
        return self.runQuery(qry).addCallbacks(self.operationDone,self.operationError)
    
    def operationDone(self, done):
        print "Done"
        self.done =0
        
    def operationError(self,err):
        print err
        

dbpool = adbapi.ConnectionPool("psycopg","dbname=%s user=%s" % (dbname,user))

db1=SomeTable(dbpool)

db1.getSomeData()

while 1 == db1.done:
        reactor.iterate()

print db1.done
print "finished"
reactor.crash()
reactor.stop()
dbpool.close()
print dbpool.connections
print reactor.running
print threading.enumerate()





More information about the Twisted-Python mailing list