0
我在我的python卡应用程序中使用线程。如何停止python中的线程
每当我按下刷新按钮,我使用线程调用一个函数,该函数被调用时,就会有另一个函数main函数里面。
我想是每当孩子函数结束。我想在不关闭应用程序或ctrl + c的情况下杀死或停止线程。
我开始线程这样
def on_refresh_mouseClick(self,event):
thread.start_new_thread(self.readalways,())
在“readalways”功能,我使用while循环中,只要条件满足,虽然循环,它会调用continuousread()函数。检查:
def readalways(self):
while 1:
cardid = self.parent.uhf.readTagId()
print "the tag id is",cardid
self.status = self.parent.db.checktagid(cardid)
if len(self.status) != 0:
break
print "the value is",self.status[0]['id']
self.a = self.status[0]['id']
self.continuesread()
def continuesread(self):
.......
.......
这continuesread读功能后,在线程应该被清除的值。
因为,如果我再次点击刷新按钮,一个新的线程正在启动,但某些值从旧线程到来。
,所以我想,当它完成了continuesread功能来杀死老线程
我的理解是否正确,因为一旦你的线程被杀死,你想关闭主应用程序?如果是这种情况,你可以使用sys.exit(),但这取决于你的主应用程序正在使用什么。 –