如何判断imaplib2空闲响应是否是由于超时导致的 [英] How to tell whether imaplib2 idle response resulted from timeout
问题描述
我正在使用 imaplib2 (
I'm using imaplib2 (docs) to interact with an IMAP server.
我正在使用带有超时和回调的idle命令.
I'm using the idle command, with a timeout and a callback.
问题是,我看不到任何方法来判断回调是由超时触发的,还是服务器上需要我签出的更改.
The problem is, I don't see any way of telling if the callback was triggered by the timeout being reached, or if there was a change on the server that I need to check out.
我每次都会得到('OK', ['IDLE terminated (Success)'])
.
这是这两种情况的调试输出:
Here's the debug output for both cases:
超时:
15:43.94 MainThread server IDLE started, timeout in 5.00 secs
15:48.94 imap.gmail.com handler server IDLE timedout
15:48.94 imap.gmail.com handler server IDLE finished
15:48.94 imap.gmail.com writer > DONE\r\n
15:49.17 imap.gmail.com reader < DDDM6 OK IDLE terminated (Success)\r\n
15:49.17 imap.gmail.com handler _request_pop(DDDM6, ('OK', ['IDLE terminated (Success)']))
发生了什么事
18:41.34 MainThread server IDLE started, timeout in 50.00 secs
19:01.35 imap.gmail.com reader < * 1 EXISTS\r\n
19:01.37 imap.gmail.com handler server IDLE finished
19:01.37 imap.gmail.com writer > DONE\r\n
19:01.59 imap.gmail.com reader < BFCN6 OK IDLE terminated (Success)\r\n
19:01.59 imap.gmail.com handler _request_pop(BFCN6, ('OK', ['IDLE terminated (Success)']))
我想念什么?
imaplib2中是否不存在该功能?
Does the functionality just not exist in imaplib2?
推荐答案
Piers Lauder(imaplib2的作者)刚刚在imaplib2-devel邮件列表中回答了这个问题.他说:
Piers Lauder (author of imaplib2) just answered this question on the imaplib2-devel mailing list. He said:
我认为测试空闲状态是否超时的方法是执行:
I think the way to test if an IDLE has timed out is to execute:
instance.response('IDLE')
它将返回:
('IDLE', ['TIMEOUT'])
如果空闲返回超时的原因,而不是
其他(例如('IDLE', [None])
).
if the reason that the idle returned as a timeout, rather than
something else (such as ('IDLE', [None])
).
我同意应对此进行记录,因此我将修复imaplib2.html 文件
I agree that this should be documented, so I'll fix the imaplib2.html document
这篇关于如何判断imaplib2空闲响应是否是由于超时导致的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!