我编写了一个带有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)也没有更新它的文本。有什么办法可以避免这种情况吗?