[Twisted-Python] Beginner's question about names and callbacks
Adan Broderick
broder79 at gmail.com
Tue Jan 27 20:19:17 EST 2009
Fantastic, that is exactly what I was looking for. Thank you very much for
helping me.
On Mon, Jan 26, 2009 at 1:46 AM, Tim Allen <screwtape at froup.com> wrote:
> On Mon, Jan 26, 2009 at 01:06:37AM -0500, Adan Broderick wrote:
> > I'm trying to write a program that will call my own function whenever a
> > query to a nameserver times out. I have figured out how to run the DNS
> > server. And I also know how to use filterAnswers(). But how do I catch
> the
> > "Failure: twisted.names.error.DNSQueryTimeoutError:" messages by adding
> code
> > to the resolver I've constructed?
>
> I'm not familiar with twisted.names, but looking at the source to
> client.Resolver, it seems that something winds up calling _lookup() with
> a timeout, which passes it off to the queryUDP() and sets up the basic
> result handling. If queryUDP() returns a result, it goes to filterAnswers,
> which checks for truncation and re-sends with queryTCP().
>
> Since the actual deferreds that deal with the timeouts are returned from
> queryUDP() and queryTCP(), it looks like you should be overriding those
> methods and capturing the results instead. Something like this:
>
> class MyResolver(client.Resolver):
>
> def _handle_query_timeout(self, fail):
> fail.trap(DNSQueryTimeoutError)
> print "Got an error:", fail.getErrorMessage()
>
> def queryUDP(self, *args, **kwargs):
> d = client.Resolver.queryUDP(self, *args, **kwargs)
> d.addErrback(self._handle_query_timeout)
> return d
>
> def queryTCP(self, *args, **kwargs):
> d = client.Resolver.queryTCP(self, *args, **kwargs)
> d.addErrback(self._handle_query_timeout)
> return d
>
> _______________________________________________
> 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: http://twistedmatrix.com/pipermail/twisted-python/attachments/20090127/9a596a95/attachment.htm
More information about the Twisted-Python
mailing list