[Twisted-Python] Re: Re: rewrite of flow.py completed

Clark C. Evans cce at clarkevans.com
Tue Apr 15 15:11:37 EDT 2003


On Tue, Apr 15, 2003 at 10:44:04AM +0200, Philippe Lafoucrière wrote:
| sorry, this was a connexion problem.

It should have raised an exception if it couldn't connect.  I think
the new flow.py (you seemed to have been using an older one) should
fix this, but perhaps not, as I haven't tested it.  

| NTL, I can't use QueryIterator with a consumer. 

Hmm.  The following should work...


  dbpool = adbapi.ConnectionPool("MySQLdb",
                                host=host,
                                db='MYDB',
                                user='USER',
                                passwd='PASS')
  sql = """SELECT nom FROM dbo_questionnaire limit 0,50"""

  def consumer()
      query = flow.Generator(QueryIterator(dbpool, sql))
      while 1:
          yield query
          if query.stop: break
          print query.result

  flow.Flow(consumer)
  flow.execute()

Or, if you want to use the twisted reactor to allow for
more than one process...

  from twisted.internet import reactor
  def res(x): print "Results : ", x
  f = flow.DeferredFlow(queryIt)
  f.addCallback(res)
  reactor.callLater(2,reactor.stop)
  reactor.run()

| I need a little more help, flow isn't easy to use if you aren't
| familiar with deferred, reactors, generators, etc.

Yes.  This stuff isn't easy.

Best,

Clark




More information about the Twisted-Python mailing list