Fantastic, that is exactly what I was looking for.&nbsp; Thank you very much for helping me. <br><br><br><div class="gmail_quote">On Mon, Jan 26, 2009 at 1:46 AM, Tim Allen <span dir="ltr">&lt;<a href="mailto:screwtape@froup.com" target="_blank">screwtape@froup.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>On Mon, Jan 26, 2009 at 01:06:37AM -0500, Adan Broderick wrote:<br>
&gt; I&#39;m trying to write a program that will call my own function whenever a<br>
&gt; query to a nameserver times out. I have figured out how to run the DNS<br>
&gt; server. And I also know how to use filterAnswers(). But how do I catch the<br>
&gt; &quot;Failure: twisted.names.error.DNSQueryTimeoutError:&quot; messages by adding code<br>
&gt; to the resolver I&#39;ve constructed?<br>
<br>
</div>I&#39;m not familiar with twisted.names, but looking at the source to<br>
client.Resolver, it seems that something winds up calling _lookup() with<br>
a timeout, which passes it off to the queryUDP() and sets up the basic<br>
result handling. If queryUDP() returns a result, it goes to filterAnswers,<br>
which checks for truncation and re-sends with queryTCP().<br>
<br>
Since the actual deferreds that deal with the timeouts are returned from<br>
queryUDP() and queryTCP(), it looks like you should be overriding those<br>
methods and capturing the results instead. Something like this:<br>
<br>
class MyResolver(client.Resolver):<br>
<br>
 &nbsp; &nbsp;def _handle_query_timeout(self, fail):<br>
 &nbsp; &nbsp; &nbsp; &nbsp;fail.trap(DNSQueryTimeoutError)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;print &quot;Got an error:&quot;, fail.getErrorMessage()<br>
<br>
 &nbsp; &nbsp;def queryUDP(self, *args, **kwargs):<br>
 &nbsp; &nbsp; &nbsp; &nbsp;d = client.Resolver.queryUDP(self, *args, **kwargs)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;d.addErrback(self._handle_query_timeout)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;return d<br>
<br>
 &nbsp; &nbsp;def queryTCP(self, *args, **kwargs):<br>
 &nbsp; &nbsp; &nbsp; &nbsp;d = client.Resolver.queryTCP(self, *args, **kwargs)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;d.addErrback(self._handle_query_timeout)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;return d<br>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">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>
</blockquote></div><br>