我有一个长期运行的python脚本,与upstart一起启动。这个脚本提出了很多请求。一切都很好,但几个小时后我开始永久性地为每个请求获得以下错误:
File "/opt/a/a-env/local/lib/python2.7/site-packages/atom/client.py", line 119, in request
File "/opt/a/a-env/local/lib/python2.7/site-packages/atom/http_core.py", line 420, in request
File "/opt/a/a-env/local/lib/python2.7/site-packages/atom/http_core.py", line 489, in _http_request
File "/usr/lib/python2.7/httplib.py", line 931, in endheaders
File "/usr/lib/python2.7/httplib.py", line 794, in _send_output
File "/usr/lib/python2.7/httplib.py", line 756, in send
File "/usr/lib/python2.7/httplib.py", line 1134, in connect
File "/usr/lib/python2.7/socket.py", line 553, in create_connection
gaierror: [Errno -3] Temporary failure in name resolution
这不是名称解析或DNS的问题,因为简单重启应用程序可以解决此问题。
我已经尝试过Python 2.6 a 2.7并且出现了同样的情况。
我正在运行Linux 2.6.35-30-virtual #61-Ubuntu SMP Tue Oct 11 18:26:36 UTC 2011 x86_64 GNU/Linux
有一些帖子有这个问题,但没有一个有简单的解释或解决方案:
答案 0 :(得分:1)
我认为当你进入“太多打开文件”状态时会发生这种情况。下次发生这种情况时,请尝试查看脚本已打开的文件描述符数。
答案 1 :(得分:0)
根本原因是/etc/resolv.conf仅在python启动时读取。要强制刷新解析表,可以运行它(在Linux上):
import ctypes
libc = ctypes.cdll.LoadLibrary('libc.so.6')
res_init = libc.__res_init
res_init()