我用 PyQt GUI 编写了一个 python 程序,它使用 imaplib 检查我是否有新邮件,下面是部分代码:
def getAccountStatus(self, accountIndex):
# some not interesting code
mail = imaplib.IMAP4_SSL(currentHost)
# some not interesting code
mail.login('user', 'pass')
mailCount = int(mail.select("INBOX", True)[1][0])
# some not interesting code
serverResponse, data = mail.uid('search', None, 'UNSEEN')
# some not interesting code
unseenUidList = data[0].split()
# some not interesting code
self.emailAccountsWidget.setText("<BR>".join(self.accountStatusString))
return [mailCount, len(unseenUidList)]
问题是,在从 imap 服务器检索数据的过程中,GUI 冻结,如果我没有显式调用窗口的重绘事件,即使 TextEdit (self.emailAccountsWidget) 也不会更新其文本。有什么办法可以避免这种情况吗?