[Twisted-Python] Strange error: SQL-Server tries to rollback

Pantelis Theodosiou ypercube at gmail.com
Fri Sep 10 13:15:17 MDT 2010


On Fri, Sep 10, 2010 at 7:39 PM, Paul Goins <general at vultaire.net> wrote:

> Thanks for the code example.
>
> I can't offer to take this work over, but maybe I can make a comment.
> There's one part that stands out to me.
>
> >          try:
> >              deferred = self.dbpool.runOperation(sql)
> >              #print("DATA sent")
> >          except Exception as e:
> >              print("error in insertDATA")
> >              print(e)
> >              return
> >          return deferred
>
> It seems like maybe you have a misunderstanding about how Deferreds
> generally work in Twisted.  (Been there myself.)  Basically, the above
> try/except block won't work to catch errors from most Deferreds... well,
> at least not without some extra magic.
>

That is correct. I have only basic understanding of Deferreds and none about
the Errbacks. I realized from various errors that this exception was raised
when errors appeared in other parts of the code.

>
> You really should read the Deferred section of the Twisted documentation
> to understand how errors are handled.
>
> Docs are here:
> http://twistedmatrix.com/documents/current/core/howto/defer.html
>
> ----
>
> Basically, to "fix" the above code's error catching, you have two choices:
>
> 1. You can add an errback to the deferred.  This is the "standard"
> Twisted way, and would replace the try/except block entirely.
>
> 2. You can use the @inlineCallbacks decorator (from
> twisted.internet.defer), and yield on the Deferred.  This is easier, and
> it allows try/except blocks, but there's some gotchas.
>
> inlineCallbacks is what I used when I was learning Twisted, and you may
> want to try that for now.  But please understand that it hides details
> about how Deferreds and callbacks really work.  When you find time, read
> the Deferred docs.
>
> ----
>
> Best of luck,
>
> - Paul Goins
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20100910/7f7f69b2/attachment.html>


More information about the Twisted-Python mailing list