Permanent 'Temporary failure in name resolution' after running for a number of hours

后端 未结 2 837
故里飘歌
故里飘歌 2020-12-15 06:21

After running for a number of hours on Linux, my Python 2.6 program that uses urllib2, httplib and threads, starts raising this error for every request:

2条回答
  •  囚心锁ツ
    2020-12-15 06:32

    Was experiencing the same issue, in my case it wasnt resource exhaustion, the problem for me happened when my dhcp server changed the nameserver address, libc did not want to play ball and reload the new resolv.conf file, maintaining the cached one and forcing me to restart the script every time it changed.

    All my python socket connections attempts fail after this, so I found this code that solved the situation:

    import ctypes
    try:
        libc = ctypes.CDLL('libc.so.6')
        res_init = getattr(libc, '__res_init')
        res_init(None)
    except:
        pass
    

    Use it before calling the socket.connect, hope this helps

提交回复
热议问题