Python线程未启动. [英] Python thread not starting.

查看:104
本文介绍了Python线程未启动.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的halt_listener线程有问题.我可以启动import_1,但是它不会产生halt_listener线程.我使用已知的良好代码来进行模式化,唯一的不同是在上一次迭代中,halt_listener获得了管道而不是队列.

I am having issues with my halt_listener thread. I can start import_1 but it will not spawn a halt_listener thread. I am patterning this after known good code, the only difference was in the last iteration the halt_listener got fed a pipe instead of a 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 
          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)

任何人都可以指出我要去哪里的地方.

Anyone have any pointers to where I am going wrong.

推荐答案

您永远不会调用t.start()来真正启动线程.

You never call t.start() to actually start the thread.

这篇关于Python线程未启动.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆