From 7144c79efeada381551e6867d82e132a92d7f405 Mon Sep 17 00:00:00 2001 From: eternnoir Date: Sun, 12 Jul 2015 15:49:22 +0800 Subject: [PATCH] Add none_stop flag for polling method. --- telebot/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index ad3ad1d..5126331 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -122,7 +122,7 @@ class TeleBot: else: listener(new_messages) - def polling(self): + def polling(self, none_stop=False): """ This function creates a new Thread that calls an internal __polling function. This allows the bot to retrieve Updates automagically and notify listeners and message handlers accordingly. @@ -130,21 +130,23 @@ class TeleBot: Do not call this function more than once! Always get updates. + :param none_stop: Do not stop polling when Exception occur. :return: """ self.__stop_polling = False - self.polling_thread = threading.Thread(target=self.__polling, args=()) + self.polling_thread = threading.Thread(target=self.__polling, args=([none_stop])) self.polling_thread.daemon = True self.polling_thread.start() - def __polling(self): + def __polling(self, none_stop): print('TeleBot: Started polling.') while not self.__stop_polling: try: self.get_update() except Exception as e: print("TeleBot: Exception occurred. Stopping.") - self.__stop_polling = True + if not none_stop: + self.__stop_polling = True print(e) print('TeleBot: Stopped polling.')