我有一个类,它设置多个线程,每个线程都会执行HTTP POST请求。在15000个请求中,我得到了大约400个失败。
Exception in thread Thread-13290:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 110, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 56, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 488, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 609, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 487, in send
raise ConnectionError(e, request=request)
ConnectionError: HTTPConnectionPool(host='some_ip_here', port=8880): Max retries exceeded with url: {some_api_endpoint} (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7f8479af71d0>: Failed to establish a new connection: [Errno 24] Too many open files',))
我在任何时候同时执行大约50个POST请求。连续100次(相隔10秒)50个并发HTTP POST请求的最佳方法是什么?