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:
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