在imap连接期间PyQt GUI冻结(imaplib)

2024-06-16 12:15:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我用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)如果不显式调用窗口的重绘事件,则不会更新其文本。有什么方法可以避免这种情况?在


Tags: self程序datanotcodeguimailsome