Kyl*_*ble 1 python multithreading typeerror
我之前从未见过这个错误:
TypeError: unbound method halt_listener() must be called with test_imports instance as first argument (got Queue instance instead)
我在运行此代码时得到它:
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
Run Code Online (Sandbox Code Playgroud)
我认为这是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'))
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3259 次 |
最近记录: |