1
我正在寫一個腳本,一旦Pibrella上的按鈕被按下,就會每隔10秒發送一封電子郵件。我希望它再次按下按鈕時停止。Pibrella + RPI線程停止
因此,例如,第一次按下時,它每隔10秒發送一封電子郵件。然後第二次,它停止線程。
這是我目前的代碼,有人可以告訴我我在哪裏做錯了嗎?
import pibrella, signal
import threading
import time
import smtplib
server = smtplib.SMTP("smtp.gmail.com",587)
server.ehlo()
server.starttls()
server.ehlo()
server.login("[email protected]", "EmailPassword")
isPressed = 0
def pressed(pin):
global isPressed
if isPressed == 0:
isPressed = 1
sendMail()
else:
pibrella.light.off()
t.cancel()
isPressed = 0
def sendMail():
pibrella.light.pulse()
server.sendmail("[email protected]", "[email protected]", "Hello World")
t.start()
t = threading.Timer(10, sendMail).start()
pibrella.button.pressed(pressed)
pibrella.pause()
server.close()
我現在正在獲取的錯誤發佈在下面。請注意,電子郵件確實正在發送。
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/pibrella.py", line 262, in handle_callback
callback(self)
File "sendText.py", line 27, in pressed
sendMail()
File "sendText.py", line 36, in sendMail
t.start()
AttributeError: 'NoneType' object has no attribute 'start'
Exception in thread Thread-14:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 760, in run
self.function(*self.args, **self.kwargs)
File "sendText.py", line 36, in sendMail
t.start()
AttributeError: 'NoneType' object has no attribute 'start'
你能告訴我們,你當前的代碼做和爲什麼你覺得會失敗? – 2014-10-07 15:33:00
用錯誤消息更新了它。 – user130622 2014-10-07 17:52:12