[Twisted-Python] SQL, Threaded, and flows

Clark C. Evans cce at clarkevans.com
Sat Aug 9 17:14:05 EDT 2003


Edmund,

   This has been fixed in the CVS repository.  In short, when flow
   was added into twisted, the "threaded" stuff seemed to be not 
   totally stable and really not core (as it is more useful with an
   async Database or LDAP driver).  Thus, QueryIterator and Threaded
   arn't imported into the flow module automatically as the example
   assumed.  You can get to these two classes via:

      from twisted.flow.threads import QueryIterator, Threaded

   And then the example should mostly work from there.  Although
   you do need an actual database connection, of course.   

Best,

Clark

[1] http://twistedmatrix.com/users/jh.twistd/viewcvs/cgi/viewcvs.cgi/doc/howto/flow.html?rev=HEAD&content-type=text/vnd.viewcvs-markup&cvsroot=Twisted

On Sat, Aug 09, 2003 at 04:35:24PM -0400, Edmund Dengler wrote:
| Hi all!
| 
| I am trying the example from the Flow HowTo page, and I have into an
| exception.
| 
| ===========================
| 
| from __future__         import generators
| from twisted.enterprise import adbapi
| from twisted.internet   import reactor
| from twisted.flow import flow
| 
| dbpool = adbapi.ConnectionPool("SomeDriver",host='localhost',
|              db='Database',user='User',passwd='Password')
| 
| sql = """
|   (SELECT 'one')
| UNION ALL
|   (SELECT 'two')
| UNION ALL
|   (SELECT 'three')
| """
| 
| def consumer():
|     query = flow.Threaded(flow.QueryIterator(dbpool, sql))
|     yield query
|     for row in query:
|         print "Processed result : ", row
| 
| from twisted.internet import reactor
| def finish(result):
|     print "Deferred Complete : ", result
| f = flow.Deferred(consumer())
| f.addBoth(finish)
| reactor.callLater(1,reactor.stop)
| reactor.run()
| 
| # prints
| # Processed result :  ('one',)
| # Processed result :  ('two',)
| # Processed result :  ('three',)
| # Deferred Complete:  []
| 
| ===========================
| 
| > python flow-query.py
| Deferred Complete :  [Failure instance: Traceback: exceptions.AttributeError, 'module' object has no attribute 'Threaded'
| /opt/python/lib/python2.2/site-packages/twisted/flow/wrap.py:100:_yield
| flow-query.py:18:consumer
| ]
| 
| Is there something I need to do? Has the API changed?
| 
| Regards!
| Ed
| 
| 
| 
| _______________________________________________
| Twisted-Python mailing list
| Twisted-Python at twistedmatrix.com
| http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python




More information about the Twisted-Python mailing list