[英]How do I increase the timeout for imaplib requests?
I'm using imaplib
to query Gmail's IMAP, but some requests are taking more than 60 seconds to return. 我正在使用
imaplib
查询Gmail的IMAP,但某些请求要花费60秒钟以上才能返回。 This is already done in a task, so I have a full 10 minutes to do the request, but my tasks are failing due to the 60 second limit on urlfetch
. 这已经在任务中完成,因此我有整整10分钟的时间来完成请求,但是由于
urlfetch
的60秒限制,我的任务失败了。
I've tried setting urlfetch.set_default_fetch_deadline(600)
, but it doesn't seem to do anything. 我尝试设置
urlfetch.set_default_fetch_deadline(600)
,但它似乎没有任何作用。
Here's a stacktrace: 这是一个堆栈跟踪:
The API call remote_socket.Receive() took too long to respond and was cancelled.
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/imaplib.py", line 760, in uid
typ, dat = self._simple_command(name, command, *args)
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/imaplib.py", line 1070, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/imaplib.py", line 897, in _command_complete
typ, data = self._get_tagged_response(tag)
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/imaplib.py", line 999, in _get_tagged_response
self._get_response()
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/imaplib.py", line 916, in _get_response
resp = self._get_line()
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/imaplib.py", line 1009, in _get_line
line = self.readline()
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/imaplib.py", line 1171, in readline
return self.file.readline()
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/socket.py", line 445, in readline
data = self._sock.recv(self._rbufsize)
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/ssl.py", line 301, in recv
return self.read(buflen)
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/ssl.py", line 220, in read
return self._sslobj.read(len)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/remote_socket/_remote_socket.py", line 864, in recv
return self.recvfrom(buffersize, flags)[0]
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/remote_socket/_remote_socket.py", line 903, in recvfrom
apiproxy_stub_map.MakeSyncCall('remote_socket', 'Receive', request, reply)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 94, in MakeSyncCall
return stubmap.MakeSyncCall(service, call, request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 328, in MakeSyncCall
rpc.CheckSuccess()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/apiproxy_rpc.py", line 133, in CheckSuccess
raise self.exception
DeadlineExceededError: The API call remote_socket.Receive() took too long to respond and was cancelled.
There are three kinds of DeadlineExceededError
in AppEngine. AppEngine中有3种
DeadlineExceededError
。
https://developers.google.com/appengine/articles/deadlineexceedederrors https://developers.google.com/appengine/articles/deadlineexceedederrors
- google.appengine.runtime.DeadlineExceededError: raised if the overall request times out, typically after 60 seconds, or 10 minutes for task queue requests.
google.appengine.runtime.DeadlineExceededError:如果总体请求超时,则通常在60秒或10分钟后(对于任务队列请求)超时而引发。
- google.appengine.runtime.apiproxy_errors.DeadlineExceededError: raised if an RPC exceeded its deadline.
google.appengine.runtime.apiproxy_errors.DeadlineExceededError:如果RPC超过其截止日期,则引发。 This is typically 5 seconds, but it is settable for some APIs using the 'deadline' option.
这通常是5秒钟,但是对于某些API,可以使用“最后期限”选项来设置。
- google.appengine.api.urlfetch_errors.DeadlineExceededError: raised if the URLFetch times out.
google.appengine.api.urlfetch_errors.DeadlineExceededError:如果URLFetch超时则引发。
As you can see. 如你看到的。 The 10mins limit of
taskqueue
only help the google.appengine.runtime.DeadlineExceededError
. 任务
taskqueue
的10分钟限制仅有助于google.appengine.runtime.DeadlineExceededError
。 The type of DeadlineExceededError
can be identified via traceback (list below). DeadlineExceededError
的类型可以通过追溯(下面列出)来识别。 In this case, it is google.appengine.runtime.apiproxy_errors.DeadlineExceededError
. 在这种情况下,它是
google.appengine.runtime.apiproxy_errors.DeadlineExceededError
。 Which will raise in 5secs by default. 默认情况下会提高5秒。 (I will update the post after figure out how to change it)
(我会在弄清楚如何更改后更新帖子)
The traceback looks like 追溯看起来像
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 266, in Handle
result = handler(dict(self._environ), self._StartResponse)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__
rv = self.router.dispatch(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__
return handler.dispatch()
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch
return method(*args, **kwargs)
File "/base/data/home/apps/s~tagtooadex2/test.371204033771063679/index.py", line 9, in get
pass
DeadlineExceededError
This exception can be solved by using taskqueue (10mins), backend or manual scaling options. 可以通过使用任务队列(10分钟),后端或手动缩放选项来解决此异常。 https://developers.google.com/appengine/docs/python/modules/#Python_Instance_scaling_and_class
https://developers.google.com/appengine/docs/python/modules/#Python_Instance_scaling_and_class
The traceback looks like 追溯看起来像
DeadlineExceededError: The API call remote_socket.Receive() took too long to respond and was cancelled.
The traceback looks like 追溯看起来像
DeadlineExceededError: Deadline exceeded while waiting for HTTP response from URL: http://www.sogi.com.tw/newforum/article_list.aspx?topic_ID=6089521
This exception can be solved by extend the deadline. 可以通过延长期限来解决此异常。
urlfetch.fetch(url, deadline=10*60)
https://developers.google.com/appengine/docs/python/urlfetch/fetchfunction https://developers.google.com/appengine/docs/python/urlfetch/fetchfunction
There's no mentioning of timeout in imaplib sources. 在imaplib源文件中没有提及超时。 So there are several options:
因此,有几种选择:
From the Google App Engine documentation , it seems like there are many possible causes for DeadlineExceededError
. 从Google App Engine文档看来,
DeadlineExceededError
可能有很多原因。
In your case, it seems that it may be one of the last two (out of three) types of DeadlineExceededError
presented on the page. 在您的情况下,它可能是页面上显示的
DeadlineExceededError
的最后两种(三种)之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.