我想让我的Python程序运行给定秒数的算法,然后打印到目前为止的最佳结果并结束。如何结束在Python中给定时间后运行的程序
这样做的最佳方法是什么?
我尝试以下,但它没有工作(该程序保持印刷后运行):
def printBestResult(self):
print(self.bestResult)
sys.exit()
def findBestResult(self,time):
self.t = threading.Timer(time, self.printBestResult)
self.t.start()
while(1):
# find best result
你能可能传递一个'SIGINT'您超时后,赶上'SIGINT'作为一个例外,中,到目前为止并退出打印的最好成绩只是块? – inspectorG4dget 2012-07-09 21:20:32