python中的无限循环导致应用程序快速冻结

python中的无限循环导致应用程序快速冻结,python,ubuntu,Python,Ubuntu,我正在尝试开发一个Ubuntu应用程序使用快速。当我在python中运行无限循环时,Ubuntu应用程序冻结并停止响应。以下是我使用的代码: # Code for other initialization actions should be added here. self.startbutton = self.builder.get_object("startbutton") def on_startbutton_clicked(self,widget): while 1

我正在尝试开发一个Ubuntu应用程序使用快速。当我在python中运行无限循环时,Ubuntu应用程序冻结并停止响应。以下是我使用的代码:

 # Code for other initialization actions should be added here.

    self.startbutton = self.builder.get_object("startbutton")
def on_startbutton_clicked(self,widget):
    while 1 :
        if "100" in open("file1.txt").read():
            print "success"
            exit ()
当我将100写入file.txt时,终端打印成功,但Ubuntu应用程序仍不会响应。那么,我应该在我的代码中做些什么更改,这样我的应用程序就不会冻结

我改变了我的while循环

 flag=1
    while flag :
        fp = open("file1.txt","r")
        if fp.read()=="100":
            print "success"
            flag=0
        fp.close()

即使这样,应用程序也会冻结

停止使用无限循环。你知道你一直在打开一个文件而不是关闭它吗?但我需要不断地读取该文件,因为当我在该文件中输入100时,我将创建一个新的来宾虚拟机。所以我应该使用无限循环,有没有无限循环的替代方法?无限循环在一个条件下中断,所以它不会永远停在那里检查?当它从该文件读取100时,循环退出