halt_listener
스레드에 문제가 있습니다. import_1
을 시작할 수는 있지만 halt_listener
스레드를 생성하지 않습니다. 나는이 좋은 코드를 알고 난 후에 이것을 패터닝하고있다. 유일한 차이점은 마지막 반복에서 halt_listener가 큐 대신에 파이프를 공급 받았다는 것이다.파이썬 스레드가 시작되지 않습니다.
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
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 import_2(self, control_queue, thread_number):
print ("Import_2 number %d started") % thread_number
count = 1
while True:
alive = control_queue.get()
count = count + 1
if alive == 't2kill':
print ("Killing thread type 2 number %d") % thread_number
return
else:
print ("Thread type 2 number %d run count %d") % (thread_number, count)
누구나 내가 잘못 가고있는 곳을 가리키는 포인터가 있습니다.
뜨아 Durp을 시작 t.start()를 추가해야합니다! 코드는 여전히 유형의 오류를 던지고 여러분을 이끌고 있지만, 그녀는 문제를 해결 적합한 –
't.start()'는 스레드를 시작하고't.run()'을 시작하지 않습니다. – Ringding
@ Ringding yep, fixed. 뇌파. – Amber