Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
wxpythonpython知道线程何时完成->卡住_Python_Wxpython_Python Multithreading_Pypubsub - Fatal编程技术网

wxpythonpython知道线程何时完成->卡住

wxpythonpython知道线程何时完成->卡住,python,wxpython,python-multithreading,pypubsub,Python,Wxpython,Python Multithreading,Pypubsub,我正在继续我的电脑检查程序。 它是基于WXPYTHON的 该程序显示一个带有标签和运行按钮的界面 单击该按钮时,将启动mainFrame类中的doCheck函数 然后,doCheck启动所有线程: Thread1 = computerCheck() Thread2 = countProcess() Thread3 = findProcess() Thread4 = findProtection() Thread5 = bitlockerCheck() Thread1.start() Threa

我正在继续我的电脑检查程序。 它是基于WXPYTHON的

该程序显示一个带有标签和运行按钮的界面 单击该按钮时,将启动mainFrame类中的doCheck函数

然后,doCheck启动所有线程:

Thread1 = computerCheck()
Thread2 = countProcess()
Thread3 = findProcess()
Thread4 = findProtection()
Thread5 = bitlockerCheck()

Thread1.start()
Thread2.start()
Thread3.start()
Thread4.start()
Thread5.start()
class findProcess(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)

    def run(self):
        my_object = dict(status='Running', result='')
        wx.CallAfter(pub.sendMessage, 'testListener', message=3,arg2=my_object)
线程正在执行一些WMI检查等,并使用pubsub.sendMessage进行报告 MainFrame类有一个侦听器函数,它在收到消息时更新GUI标签

到目前为止还不错!allis工作得很好。 但是现在我想知道所有启动的线程何时完成。这就是问题所在。。。 如果我在线程上使用连接,则在所有线程完成之前,PUBSUB GUI更新不会工作。 如果我在doCheck函数中使用while语句循环isAlive,它基本上也会这样做,等待一切结束。再一次,PUBSUB也停止了

所以我被困在这里了。到目前为止,该程序运行良好,但现在我需要在所有检查完成/完成后启动下一步,但我不知道如何在不阻止PUBSUB的运行时更新的情况下完成这一步

实际线程的片段:

Thread1 = computerCheck()
Thread2 = countProcess()
Thread3 = findProcess()
Thread4 = findProtection()
Thread5 = bitlockerCheck()

Thread1.start()
Thread2.start()
Thread3.start()
Thread4.start()
Thread5.start()
class findProcess(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)

    def run(self):
        my_object = dict(status='Running', result='')
        wx.CallAfter(pub.sendMessage, 'testListener', message=3,arg2=my_object)
备注:消息参数用于知道哪些标签应更新

有什么建议吗?我可以在需要时发布更多代码


谢谢

解决方案之一是:

启动另一个将加入的线程,当所有线程都加入后,向主线程发布消息。收到该消息后,您知道线程已完成,您可以继续工作

或者,这一个有点粗俗:创建一个函数,每100毫秒检查一次所有线程是否处于活动状态。类似如下:

def check_threads_finished(self):
    for i in self.my_threads:
        if i.is_alive():
            wx.CallLater(100, self.check_threads_finished)
            return
    # finished
    self.do_whatever_is_needed_after_threads_finished()