[Twisted-Python] adbapi question
Justin Ryan
justin at gnubia.net
Wed Apr 30 19:29:01 MDT 2003
Someone will surely correct me if I'm wrong, but I ran into this same
dilemma when I began to use twisted. It seems that as twisted is an
event-driven framework for asynchronous networked applications, it isn't
intended to be used in this way.
Twisted applications should generally sit around waiting for requests,
and respond to them in a timely, but non-blocking manner. Starting up,
doing some stuff, and exiting, just doesn't seem to be the idiom at play
here.
YMMV..
On Wed, 2003-04-30 at 17:28, Jon Dyte wrote:
> 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()
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: </pipermail/twisted-python/attachments/20030430/0b1471b7/attachment.sig>
More information about the Twisted-Python
mailing list