I configure the bot and run it from the desktop application in a separate thread, forcing it to execute bot.polling (none_stop = True).
class TelegramBot(Thread): def __init__(self): Thread.__init__(self) self.GlobalBot = telebot.TeleBot(config.token, threaded=False) self.LocalBot = MainBot() @self.GlobalBot.message_handler(func=lambda message: True, content_types=['text']) def send_msg(message): self.GlobalBot.send_message(message.chat.id, self.LocalBot.GetAnswer(message.text)) self.Started =1 def __StartTele(self): self.LocalBot.ReConnectToDB() self.GlobalBot.polling(none_stop=True) def run(self): self.__StartTele() def stop(self): self.__StopTele() #self._stop_event.set() def __StopTele(self): self.GlobalBot.stop_polling() Everything works as it should: in the application I press the button that initializes this class and executes bot.polling (), but if I press the button that should turn off the bot and executes bot.stop_polling (), then nothing happens. The bot continues to drive its stream, even when I close the application, until I forcibly close the interpreter.
So how can I turn off the bot without shutting down the program?