[Twisted-Python] adbapi question
Jon Dyte
jon at totient.demon.co.uk
Thu May 1 15:35:44 MDT 2003
On Thursday 01 May 2003 2:38 am, Itamar Shtull-Trauring wrote:
> On Wed, 30 Apr 2003 23:28:31 +0100
>
> Jon Dyte <jon at totient.demon.co.uk> wrote:
> > 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.
>
> You don't want a reactor.crash() and a reactor.stop(). Just do
> reactor.stop().
>
> Using threads can make your python program not exit if they hang around,
> but reactor.stop() should shut down all threads in the thread pool.
I added just reactor.stop(), but it doesnt work.
eg :-
$ python simpledb.py jon jon jon
Done
0
finished
{1026: <connection object at 0x82282c0>}
[<_MainThread(MainThread, started)>, <Thread(PoolThread-136416444-1,
started)>]
The thread isnt removed from the threadpool.
I get the same problem with the Sybase DB-API module as well as psycopg
The script is
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.stop()
print dbpool.connections
print threading.enumerate()
Jon
More information about the Twisted-Python
mailing list