使用threading.timer来延迟子程序

时间:2015-05-17 18:06:33

标签: python-3.x pyqt4 self

def emailCheck(self):
n=0
(retcode, messages) = mail.search(None, '(UNSEEN)')
if retcode == 'OK':

    for num in messages[0].split() :
        n=n+1
        typ, data = mail.fetch(num,'(RFC822)')
        for response_part in data:
            if isinstance(response_part, tuple):
                original = email.message_from_bytes(response_part[1])

                print (original['From'])
                print (original['Subject'])
                typ, data = mail.store(num,'+FLAGS','\\Seen')
print (n)

t = threading.Timer(10.0, emailCheck)
t.start()

我试图使用threading.timer()来延迟子过程,但我认为错误是在括号中包含self。我正在使用PyQt,因此所有这些都包含在MainWindow类中。

错误:

Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Python33\lib\threading.py", line 637, in _bootstrap_inner
self.run()
File "C:\Python33\lib\threading.py", line 823, in run
self.function(*self.args, **self.kwargs)
TypeError: emailCheck() missing 1 required positional argument: 'self'

1 个答案:

答案 0 :(得分:0)

t = threading.Timer(10.0,self.emailCheck)