From 766b45e223b89c30af96320452b11af290e463a6 Mon Sep 17 00:00:00 2001 From: FrankWang Date: Fri, 17 Jul 2015 21:40:33 +0800 Subject: [PATCH 1/2] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 3b2e1cd..c81575b 100644 --- a/README.md +++ b/README.md @@ -237,6 +237,12 @@ while True: # Don't end the main thread. ``` Use whichever mechanism fits your purpose! It is even possible to mix and match. +## Telegram Chat Group + +Get help. Discuss. Chat. + +Join [pyTelegramBotAPI Chat Group](https://telegram.me/joinchat/067e22c60035523fda8f6025ee87e30b). + ## Examples * [Echo Bot](https://github.com/eternnoir/pyTelegramBotAPI/blob/master/examples/echo_bot.py) From edddab8956a1817effbe061e0f6b3684f89ecfec Mon Sep 17 00:00:00 2001 From: Nathanael Farley Date: Sat, 18 Jul 2015 10:27:16 +0100 Subject: [PATCH 2/2] Changed __stop_polling from bool to threading.Event(). --- telebot/__init__.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 9e60aec..b1760e0 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -88,7 +88,7 @@ class TeleBot: self.token = token self.update_listener = [] self.polling_thread = None - self.__stop_polling = False + self.__stop_polling = threading.Event() self.last_update_id = 0 self.num_threads = num_threads self.__create_threads = create_threads @@ -136,30 +136,29 @@ class TeleBot: :param none_stop: Do not stop polling when Exception occur. :return: """ - self.__stop_polling = True + self.__stop_polling.set() if self.polling_thread: self.polling_thread.join() # wait thread stop. - self.__stop_polling = False + self.__stop_polling.clear() self.polling_thread = threading.Thread(target=self.__polling, args=([none_stop, interval])) self.polling_thread.daemon = True self.polling_thread.start() def __polling(self, none_stop, interval): print('TeleBot: Started polling.') - while not self.__stop_polling: + while not self.__stop_polling.wait(interval): try: self.get_update() except Exception as e: if not none_stop: - self.__stop_polling = True + self.__stop_polling.set() print("TeleBot: Exception occurred. Stopping.") print(e) - time.sleep(interval) print('TeleBot: Stopped polling.') def stop_polling(self): - self.__stop_polling = True + self.__stop_polling.set() def set_update_listener(self, listener): self.update_listener.append(listener)