From 4a3e9893912d613c16c922cd179cf1475488873d Mon Sep 17 00:00:00 2001 From: eternnoir Date: Sun, 12 Jul 2015 15:49:22 +0800 Subject: [PATCH 1/2] 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.') From 292bb307f00bb1a00bc6bcec268ab5b51a525e5f Mon Sep 17 00:00:00 2001 From: eternnoir Date: Sun, 12 Jul 2015 19:03:41 +0800 Subject: [PATCH 2/2] Edit confused notice. --- telebot/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 5126331..0111678 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -144,9 +144,9 @@ class TeleBot: try: self.get_update() except Exception as e: - print("TeleBot: Exception occurred. Stopping.") if not none_stop: self.__stop_polling = True + print("TeleBot: Exception occurred. Stopping.") print(e) print('TeleBot: Stopped polling.')