Best strategy for overcoming excessive gethostbyname timeout.

John Bokma john at castleamber.com
Fri Nov 27 21:04:51 EST 2009


r0g <aioe.org at technicalbloke.com> wrote:

> It seems gethostbyname asks the OS to resolve the address and the OS
> uses it's own timeout value ( 25 seconds ) rather than the one provided
> in setdefaulttimeout. 25 seconds of blocking is way too long for me, I
> want the response within 5 seconds or not at all but I can see no
> reasonable way to do this without messing with the OS which naturally I
> am loathe to do!

use signal.alarm(time) to send SIGALRM to your process:
http://docs.python.org/library/signal.html#signal.alarm
See example at bottom.

John



More information about the Python-list mailing list