我需要能够调用运行线程的停止函数。我尝试了几种方法来达到这个目的,但至今没有成功。我想我需要一个线程id,但不知道如何做到这一点。你知道吗
相关代码: 型号:
import MODULE
class do_it():
def __init__(self):
self.on_pushButton_start_clicked()
return
def on_pushButton_start_clicked(self):
self.Contr = MODULE.Controller()
self.Contr.start()
def on_pushButton_stop_clicked(self):
if self.Contr:
self.Contr.stop()
self.Contr = None
return
模块:
import thread
class Controller():
def __init__(self):
self.runme = False
def start(self):
"""Using this to start the controllers eventloop."""
thread.start_new_thread(self._run, ())
def stop(self):
"""Using this to stop the eventloop."""
self.runme = False
def _run(self):
"""The actual eventloop"""
self.runme = True
我想我的问题就在这里…
我的控制器:
"""I want to use this to control my model, that in turn controls the module"""
def start_module():
start=do_it().on_pushButton_start_clicked()
return 'Ran start function'
def stop_module():
stop=do_it().on_pushButton_stop_clicked()
return 'Ran stop function'
关于
thread
模块,文档是这么说的:此外,一旦线程启动,就无法停止或终止它。This所以问题会更详细,并展示如何使用
threading.Event
实现可停止线程。你知道吗唯一的区别是daemon thread,它将在主程序存在时自动终止。你知道吗
相关问题 更多 >
编程相关推荐