1
2019-07-21 10:56:02.514949 app[web.1]:  Exception in thread Thread-2:
2019-07-21 10:56:02.514963 app[web.1]:  Traceback (most recent call last):
2019-07-21 10:56:02.514965 app[web.1]:  File "/app/.heroku/python/lib/python3.7/site-packages/urllib3/connectionpool.py", line 384, in _make_request
2019-07-21 10:56:02.514967 app[web.1]:  six.raise_from(e, None)
2019-07-21 10:56:02.514969 app[web.1]:  File "<string>", line 2, in raise_from
2019-07-21 10:56:02.514971 app[web.1]:  File "/app/.heroku/python/lib/python3.7/site-packages/urllib3/connectionpool.py", line 380, in _make_request
2019-07-21 10:56:02.514973 app[web.1]:  httplib_response = conn.getresponse()
2019-07-21 10:56:02.514976 app[web.1]:  File "/app/.heroku/python/lib/python3.7/http/client.py", line 1321, in getresponse
2019-07-21 10:56:02.514978 app[web.1]:  response.begin()
2019-07-21 10:56:02.514980 app[web.1]:  File "/app/.heroku/python/lib/python3.7/http/client.py", line 296, in begin
2019-07-21 10:56:02.514982 app[web.1]:  version, status, reason = self._read_status()
2019-07-21 10:56:02.514985 app[web.1]:  File "/app/.heroku/python/lib/python3.7/http/client.py", line 257, in _read_status
2019-07-21 10:56:02.514987 app[web.1]:  line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
2019-07-21 10:56:02.514989 app[web.1]:  File "/app/.heroku/python/lib/python3.7/socket.py", line 589, in readinto
2019-07-21 10:56:02.514991 app[web.1]:  return self._sock.recv_into(b)
2019-07-21 10:56:02.514996 app[web.1]:  socket.timeout: timed out
2019-07-21 10:56:02.514999 app[web.1]:
2019-07-21 10:56:02.515001 app[web.1]:  During handling of the above exception, another exception occurred:
2019-07-21 10:56:02.515003 app[web.1]:
2019-07-21 10:56:02.515005 app[web.1]:  Traceback (most recent call last):
2019-07-21 10:56:02.515007 app[web.1]:  File "/app/.heroku/python/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
2019-07-21 10:56:02.515009 app[web.1]:  timeout=timeout
2019-07-21 10:56:02.515011 app[web.1]:  File "/app/.heroku/python/lib/python3.7/site-packages/urllib3/connectionpool.py", line 638, in urlopen
2019-07-21 10:56:02.515013 app[web.1]:  _stacktrace=sys.exc_info()[2])
2019-07-21 10:56:02.515015 app[web.1]:  File "/app/.heroku/python/lib/python3.7/site-packages/urllib3/util/retry.py", line 367, in increment
2019-07-21 10:56:02.515018 app[web.1]:  raise six.reraise(type(error), error, _stacktrace)
2019-07-21 10:56:02.515020 app[web.1]:  File "/app/.heroku/python/lib/python3.7/site-packages/urllib3/packages/six.py", line 686, in reraise
2019-07-21 10:56:02.515022 app[web.1]:  raise value
2019-07-21 10:56:02.515024 app[web.1]:  File "/app/.heroku/python/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
2019-07-21 10:56:02.515026 app[web.1]:  chunked=chunked)
2019-07-21 10:56:02.515028 app[web.1]:  File "/app/.heroku/python/lib/python3.7/site-packages/urllib3/connectionpool.py", line 386, in _make_request
2019-07-21 10:56:02.515030 app[web.1]:  self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
2019-07-21 10:56:02.515032 app[web.1]:  File "/app/.heroku/python/lib/python3.7/site-packages/urllib3/connectionpool.py", line 306, in _raise_timeout
2019-07-21 10:56:02.515034 app[web.1]:  raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
2019-07-21 10:56:02.515038 app[web.1]:  urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='sarabot2.herokuapp.com', port=80): Read timed out. (read timeout=50)
2019-07-21 10:56:02.515039 app[web.1]:
2019-07-21 10:56:02.515041 app[web.1]:  During handling of the above exception, another exception occurred:
2019-07-21 10:56:02.515044 app[web.1]:
2019-07-21 10:56:02.515046 app[web.1]:  Traceback (most recent call last):
2019-07-21 10:56:02.515048 app[web.1]:  File "/app/.heroku/python/lib/python3.7/threading.py", line 917, in _bootstrap_inner
2019-07-21 10:56:02.515050 app[web.1]:  self.run()
2019-07-21 10:56:02.515052 app[web.1]:  File "/app/.heroku/python/lib/python3.7/threading.py", line 865, in run
2019-07-21 10:56:02.515054 app[web.1]:  self._target(*self._args, **self._kwargs)
2019-07-21 10:56:02.515056 app[web.1]:  File "/app/app.py", line 1055, in restart
2019-07-21 10:56:02.515058 app[web.1]:  requests.head(f'http://{domain}.herokuapp.com/gtcheck',timeout=50)
2019-07-21 10:56:02.515060 app[web.1]:  File "/app/.heroku/python/lib/python3.7/site-packages/requests/api.py", line 101, in head
2019-07-21 10:56:02.515062 app[web.1]:  return request('head', url, **kwargs)
2019-07-21 10:56:02.515064 app[web.1]:  File "/app/.heroku/python/lib/python3.7/site-packages/requests/api.py", line 60, in request
2019-07-21 10:56:02.515066 app[web.1]:  return session.request(method=method, url=url, **kwargs)
2019-07-21 10:56:02.515068 app[web.1]:  File "/app/.heroku/python/lib/python3.7/site-packages/requests/sessions.py", line 524, in request
2019-07-21 10:56:02.515070 app[web.1]:  resp = self.send(prep, **send_kwargs)
2019-07-21 10:56:02.515072 app[web.1]:  File "/app/.heroku/python/lib/python3.7/site-packages/requests/sessions.py", line 637, in send
2019-07-21 10:56:02.515075 app[web.1]:  r = adapter.send(request, **kwargs)
2019-07-21 10:56:02.515076 app[web.1]:  File "/app/.heroku/python/lib/python3.7/site-packages/requests/adapters.py", line 529, in send
2019-07-21 10:56:02.515078 app[web.1]:  raise ReadTimeout(e, request=request)
2019-07-21 10:56:02.515081 app[web.1]:  requests.exceptions.ReadTimeout: HTTPConnectionPool(host='sarabot2.herokuapp.com', port=80): Read timed out. (read timeout=50)
2019-07-21 10:56:02.515083 app[web.1]:

@app.before_serving导致这个吗?


线程 Thread-2 中的异常:发生的地方

4

1 回答 1

1

@app.before_serving 会导致这个吗?

是的,如果@app.before_serving装饰函数没有完成,应用程序将不会开始处理请求。在您的情况下,它似乎sarabot2.herokuapp.com没有及时回复您的请求。

另请注意,这requests是同步的,因此会阻塞事件循环,aiohttp(或requests-async)将是更好的选择。

于 2019-07-21T12:17:56.930 回答