Python线程错误组参数现在必须为None

2024-04-23 17:50:10 发布

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

我遇到了以下错误,你知道是什么引起的吗

Traceback (most recent call last):
   File "test.py", line 42, in <module>
    click_thread = RegisterC(delay, button)
   File "C:\Users\pc\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 781, in __init__
    assert group is None, "group argument must be None for now" 
AssertionError: group argument must be None for now
delay = 0.01
button = Button.left
start_stop_key = KeyCode(char='w')
exit_key = KeyCode(char='s')


class RegisterC(threading.Thread):
    def init(self, delay, button):
        super(RegisterC, self).init()
        self.delay = delay
        self.button = button
        self.running = False
        self.program_running = True

    def start_clicking(self):
        self.running = True

    def stop_clicking(self):
        self.running = False

    def exit(self):
        self.stop_clicking()
        self.program_running = False

    def run(self):
        while self.program_running:
            while self.running:
                mouse.click(self.button)
                time.sleep(random.uniform(20,60))
                time.sleep(0.1)


mouse = MouseController()
keyboard = KeyboardController()
click_thread = RegisterC(delay, button)
click_thread.start()

Tags: selfnonefalseinitdefgroupbuttonprogram
1条回答
网友
1楼 · 发布于 2024-04-23 17:50:10

对象初始化期间调用的神奇方法是__init__而不是init,您需要应用此修复程序:

class RegisterC(threading.Thread):
    def __init__(self, delay, button):
        super(RegisterC, self).__init__()
        self.delay = delay
        self.button = button
        self.running = False
        self.program_running = True

在调用方法init时,没有覆盖基类构造函数,因此在这一行click_thread = RegisterC(delay, button)上给RegisterC的参数被传递给了Thread.__init__,它期望group作为第一个参数,并将其断言为None

相关问题 更多 >