[Twisted-Python] run queries in deffered, but not in transaction

Amaury Forgeot d'Arc amauryfa at gmail.com
Thu Sep 17 03:32:13 EDT 2009


2009/9/17 Matt Perry <matt at unshift.net>:
> Make sure you're using the @inlineCallbacks decorator and the yield
> statement referenced previously.  Without those you're just adding several
> callbacks to the same Deferred; with them, the function will wait until the
> Deferred fires before continuing.
> def logRequest(self, *arg, **kw):
>    obj = copy.deepcopy(kw['obj'])
>    d = self.db.runInteraction(obj.first)
>    d.addCallback(self.db.runInteraction, obj.second, param1, param2)
>    d.addErrback(log.err)
>    d.addCallback(self.db.runInteraction, obj.third)
>    d.addErrback(log.err)

I don't understand your explanation. When a callback returns a Deferred itself,
the main Deferred object waits for its completion before continuing.
This is IMO the best feature of Deferreds!

I often write code like the function above, so I would like to understand why
it does not work in this case.

Amaury Forgeot d'Arc

More information about the Twisted-Python mailing list