我希望触发upfunction
并在文件名中写入3时停止。基本上,我想要一旦满足条件就停止线程,如下所示。
def getstatus():
fh = open(filename,'r')
return fh.read()
def upfunction(arg):
for i in range(arg):
print ("backup running")
print(getstatus())
target = open(filename, 'w')
target.write(str(i))
sleep(1)
if __name__ == "__main__":
thread = Thread(target = upfunction, args = (10, ))
thread.start()
print(getstatus())
while getstatus() != "3":
print("NOT 3 ")
sleep(0.5)
continue
thread.stop()
print("thread finished...exiting")
这显示:
属性错误:'Thread'对象没有属性'stop'
请把我当作Python的新手。任何帮助将不胜感激。