Python 2.7 线程停止Tkinter程序的执行

Python 2.7 线程停止Tkinter程序的执行,python-2.7,tkinter,background-process,python-multithreading,Python 2.7,Tkinter,Background Process,Python Multithreading,嘿,我正在编写一个与jenkins一起工作的接口来触发构建作业和部署。我一直坚持的一个特性是,一旦构建完成,就能够获得构建的状态 到目前为止,我已经用Tkinter实现了一个GUI,除了缺少关于最终构建状态的信息外,该应用程序功能齐全 我试图轮询jenkins以获取信息,但我需要在轮询之前给它时间完成构建。我想我可以通过一个简单的线程来实现这一点,然后让它在后台运行,然而,当线程运行时,它会命中time.sleep()函数,它也会停止程序的其余部分 这是否可以在不停止程序的其余部分(即GUI)的

嘿,我正在编写一个与jenkins一起工作的接口来触发构建作业和部署。我一直坚持的一个特性是,一旦构建完成,就能够获得构建的状态

到目前为止,我已经用Tkinter实现了一个GUI,除了缺少关于最终构建状态的信息外,该应用程序功能齐全

我试图轮询jenkins以获取信息,但我需要在轮询之前给它时间完成构建。我想我可以通过一个简单的线程来实现这一点,然后让它在后台运行,然而,当线程运行时,它会命中time.sleep()函数,它也会停止程序的其余部分

这是否可以在不停止程序的其余部分(即GUI)的情况下实现,如果可以,我会错在哪里

以下是问题领域的一个小片段:

def checkBuildStatus(self):
    monitor_thread = threading.Thread(target=self._pollBuild())
    monitor_thread.daemon = True
    monitor_thread.start()

def _pollBuild(self):
    # now sleep until the build is done
    time.sleep(15)

    # get the build info for the last job
    build_info = self.server.get_build_info(self.current_job, self.next_build_number)
    result = build_info['result']

创建线程时,需要传递函数本身。确保不要调用该函数

monitor_thread = threading.Thread(target=self._pollBuild())
#                                                       ^^
应该是:

monitor_thread = threading.Thread(target=self._pollBuild)

创建线程时,需要传递函数本身。确保不要调用该函数

monitor_thread = threading.Thread(target=self._pollBuild())
#                                                       ^^
应该是:

monitor_thread = threading.Thread(target=self._pollBuild)

工作就像一个符咒,有道理我在主线上调用它却没有意识到。非常感谢。工作就像一个符咒,有道理我在主线上调用它却没有意识到。非常感谢。