AssertionError:对于现在的python,group参数必须为None

时间:2018-06-09 06:45:30

标签: python raspberry-pi iot python-multithreading

我正在使用PIR传感器来查明是否存在入侵者。如果入侵者存在它将进入睡眠1分钟现在我必须重置睡眠时间,因为我使用线程但它显示断言错误,帮助我,下面是我的代码。

from threading import Thread, Event
import time

import RPi.GPIO as GPIO


class MyThread(Thread):
    def __ini(self, timeout=60):
        self.intruder_spotted = Event()
        self.timeout = timeout

        self.daemon = True

    def run(self):
        while True:
            if self.intruder_spotted.wait(self.timeout):
                self.intruder_spotted.clear()
                print("Intruder")
            else:
                print("No intruder")



t = MyThread(60)

GPIO.setmode(GPIO.BCM)
GPIO.setup(18,GPIO.IN)

try:
    t.start()
    while True:
        i=GPIO.input(18)
        if i==1:
            t.intruder_spotted.set()

        time.sleep(1)

except KeyboardInterrupt:
    GPIO.cleanup()
    exit(0)

1 个答案:

答案 0 :(得分:1)

需要更新我的Thread类的int。它的__init__不是__ini。并使用super

调用父init
class MyThread(Thread): 
    def__init__(self, timeout=60):
    super(MyThread, self).__init__()
    self.intruder_spotted = Event()
    self.timeout = timeout
    self.daemon = True