gpt4 book ai didi

python 类型错误: unbound method error

转载 作者:太空宇宙 更新时间:2023-11-04 09:07:53 24 4
gpt4 key购买 nike

我以前从未见过这个错误:

TypeError:必须使用 test_imports 实例作为第一个参数调用未绑定(bind)方法 halt_listener()(取而代之的是 Queue 实例)

当我运行这段代码时我明白了:

class test_imports:#Test classes remove 
alive = {'import_1': True, 'import_2': True};

def halt_listener(self, control_Queue, thread_Name, kill_command):
while True:
print ("Checking queue for kill")
isAlive = control_queue.get()
print ("isAlive", isAlive)
if isAlive == kill_command:
print ("kill listener triggered")
self.alive[thread_Name] = False;
return

def import_1(self, control_Queue, thread_Number):
print ("Import_1 number %d started") % thread_Number
t = Thread(target=test_imports.halt_listener, args=(control_Queue, 'import_1', 't1kill'))
count = 0
t.run()
global alive
run = test_imports.alive['import_1'];
while run:
print ("Thread type 1 number %d run count %d") % (thread_Number, count)
count = count + 1
print ("Test Import_1 ", run)
run = self.alive['import_1'];
print ("Killing thread type 1 number %d") % thread_Number

我认为是这一行 def halt_listener(self, control_Queue, thread_Name, kill_command): 特别是 self 但我不确定是否有人有任何指导我应该如何处理这个?谢谢!

最佳答案

您必须先创建类的实例:

def import_1(self, control_Queue, thread_Number):
print ("Import_1 number %d started") % thread_Number
myinstance = test_imports()
t = Thread(target=myinstance.halt_listener, args=(control_Queue, 'import_1', 't1kill'))

关于 python 类型错误: unbound method error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18294845/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com