Python socket.gethostbyaddr () - reduce latency?

socket.gethostbyname() works fine when its argument is a true hostname. But when it is a non-existent host, I get a 3 second timeout followed by

 socket.gaierror: [Errno 11001] getaddrinfo failed 

I am not against exception (it fits), but is there a way to reduce the timeout?

+4
source share
1 answer

This may not be possible if Python uses the gethostbyname() . I'm not sure if you really want this because you can get false timeouts.

As soon as I had a similar problem, but from C ++: I had to call a function for a large number of names, so a long timeout was a real pain. The solution was to call it from many threads in parallel, so although some of them were stuck waiting for a timeout, all the others went fine.

+1
source

Source: https://habr.com/ru/post/1390912/


All Articles