【问题标题】:Behavior of thread that "finished" on it's own?自己“完成”的线程的行为?
【发布时间】:2012-06-06 12:50:05
【问题描述】:

如果线程目标完成执行(__do_loop__ 设置为 True),线程对象是否会自行删除?我可以再次运行start_event_loop 而不出现任何问题吗?

我想在 WxPython 程序中使用这种行为,refuses to terminate when an object contains a running thread

def event_loop(self):
    while self.__do_loop__ == True:
        ...stuff

def start_event_loop(self):
    self.__do_loop__ = True
    self.__thread__ = Thread(target = self.event_loop, args=())
    self.__thread__.start()

【问题讨论】:

  • 您不应该将__xyz__ 用于您的变量/方法!请改用_xyz
  • 将 daemon 属性设置为 True 将允许您的 wx 应用正常关闭

标签: python multithreading


【解决方案1】:

您仍然必须在线程对象上调用join,除非它处于守护程序模式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-29
    • 1970-01-01
    • 2012-12-01
    • 2021-05-10
    相关资源
    最近更新 更多