0

嘿,我正在编写一个接口,与詹金斯一起工作来触发构建作业和部署。我一直坚持的一个特点是能够在完成构建后获得构建状态。线程暂停执行Tkinter程序

截至目前,我有一个与Tkinter实现的GUI和应用程序是完全正常运行,除了在最终的构建状态丢失的信息。

我试图查询jenkins的信息,但我需要给它时间来完成轮询之前的构建。我以为我可以通过一个简单的线程来完成这个任务,并且只是让它在后台运行,但是,当线程运行并且它触发time.sleep()函数时,它会暂停程序的其余部分。

这样做可以不停止程序的其余部分,即GUI,如果是这样,我会在哪里出错?

这里的问题区域的SNIPPIT:

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'] 

回答

3

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

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

应该是:

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

工作就像一个魅力,是有道理的我在呼唤它在主线程没有意识到这一点。谢谢! –