【问题标题】:How to destroy all threads on KeyboardInterrupt (Destroying Main App)?如何销毁 KeyboardInterrupt 上的所有线程(销毁主应用程序)?
【发布时间】:2019-05-02 17:52:16
【问题描述】:

我有主应用程序,我可以用聊天机器人打开线程。

def run_bot(self):
    bot = TelegramBot(self.engine.CurrentBot)
    bot.start()

然后我要关闭我的应用程序,我需要销毁我所有的踏板。我在 PyCharm 中使用停止按钮。它返回KeyboardInterrupt,但不会杀死机器人。他们正在继续使用应用程序。

Telegram bot 是Thread 的子类

【问题讨论】:

    标签: python python-3.x multithreading class thread-safety


    【解决方案1】:

    当你停止主进程时,所有的子线程都会被自动杀死。您可能需要在 PyCharm 中按两次停止按钮,首先要终止主线程,然后在显示骷髅标志后,按该骷髅以终止整个进程(以及所有子线程)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-15
      相关资源
      最近更新 更多