<br><br><div class="gmail_quote">On Fri, Sep 10, 2010 at 7:39 PM, Paul Goins <span dir="ltr"><<a href="mailto:general@vultaire.net">general@vultaire.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Thanks for the code example.<br>
<br>
I can't offer to take this work over, but maybe I can make a comment.<br>
There's one part that stands out to me.<br>
<div class="im"><br>
> try:<br>
> deferred = self.dbpool.runOperation(sql)<br>
> #print("DATA sent")<br>
> except Exception as e:<br>
> print("error in insertDATA")<br>
> print(e)<br>
> return<br>
> return deferred<br>
<br>
</div>It seems like maybe you have a misunderstanding about how Deferreds<br>
generally work in Twisted. (Been there myself.) Basically, the above<br>
try/except block won't work to catch errors from most Deferreds... well,<br>
at least not without some extra magic.<br></blockquote><div><br>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. <br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
You really should read the Deferred section of the Twisted documentation<br>
to understand how errors are handled.<br>
<br>
Docs are here:<br>
<a href="http://twistedmatrix.com/documents/current/core/howto/defer.html" target="_blank">http://twistedmatrix.com/documents/current/core/howto/defer.html</a><br>
<br>
----<br>
<br>
Basically, to "fix" the above code's error catching, you have two choices:<br>
<br>
1. You can add an errback to the deferred. This is the "standard"<br>
Twisted way, and would replace the try/except block entirely.<br>
<br>
2. You can use the @inlineCallbacks decorator (from<br>
twisted.internet.defer), and yield on the Deferred. This is easier, and<br>
it allows try/except blocks, but there's some gotchas.<br>
<br>
inlineCallbacks is what I used when I was learning Twisted, and you may<br>
want to try that for now. But please understand that it hides details<br>
about how Deferreds and callbacks really work. When you find time, read<br>
the Deferred docs.<br>
<br>
----<br>
<br>
Best of luck,<br>
<font color="#888888"><br>
- Paul Goins<br>
</font><div><div></div><div class="h5"><br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</div></div></blockquote></div><br>