Fantastic, that is exactly what I was looking for. 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"><<a href="mailto:screwtape@froup.com" target="_blank">screwtape@froup.com</a>></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>
> I'm trying to write a program that will call my own function whenever a<br>
> query to a nameserver times out. I have figured out how to run the DNS<br>
> server. And I also know how to use filterAnswers(). But how do I catch the<br>
> "Failure: twisted.names.error.DNSQueryTimeoutError:" messages by adding code<br>
> to the resolver I've constructed?<br>
<br>
</div>I'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>
def _handle_query_timeout(self, fail):<br>
fail.trap(DNSQueryTimeoutError)<br>
print "Got an error:", fail.getErrorMessage()<br>
<br>
def queryUDP(self, *args, **kwargs):<br>
d = client.Resolver.queryUDP(self, *args, **kwargs)<br>
d.addErrback(self._handle_query_timeout)<br>
return d<br>
<br>
def queryTCP(self, *args, **kwargs):<br>
d = client.Resolver.queryTCP(self, *args, **kwargs)<br>
d.addErrback(self._handle_query_timeout)<br>
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>