Twisted adbapi fetchone -
if use runinteraction of twisted's adbapi, , within function call like
curs. execute("select id mytable name='bob'") id = curs.fetchone()[0]
am guaranteed id select or 1 of other deferred threads?
deferreds thread-safe can guarantee.
example code lookslike:
def _getage(txn, user): # run in thread, can use blocking calls txn.execute("select * foo") # ... other cursor commands called on txn ... txn.execute("select age users name = ?", user) result = txn.fetchall() if result: return result[0][0] else: return none def getage(user): return dbpool.runinteraction(_getage, user) def printresult(age): if age != none: print age, "years old" else: print "no such user" getage("joe").addcallback(printresult)
this official docs. didn't remove row more clear , teaching.
Comments
Post a Comment