你不应该打电话
Process.__init__
Alarm.run
! 你已经在做了
Alarm.__init__
Process.__init__(self)
与完全相同
super().__init__()
这是否有帮助:
import threading
import time
class Alarm(threading.Thread):
def run(self):
#code
#if motion detected sendmail, and run the siren:
siren = Siren() #actually, problem here: I need to import the class
#and declare this in the main Flask app file, so as
#to be able to control it from the GUI. Apparently I
#can't declare it in both python files (sounds
#obvious though)
siren.start()
#then keep looping
for x in range(20):
print ".",
time.sleep(1)
siren.term()
siren.join()
class Siren(threading.Thread):
def run(self):
self.keepRunning=True;
while self.keepRunning:
print "+",
time.sleep(1)
def term(self):
self.keepRunning=False
if __name__ == '__main__':
alarm = Alarm()
alarm.run()
+. + . .+ . + +. +. . + . + . + . + + . + . + . + . + . + . + . + . +. +. +