1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Add none_stop flag for polling method.

This commit is contained in:
eternnoir 2015-07-12 15:49:22 +08:00
parent 09a39fcb89
commit 4a3e989391

View File

@ -122,7 +122,7 @@ class TeleBot:
else: else:
listener(new_messages) 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 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. This allows the bot to retrieve Updates automagically and notify listeners and message handlers accordingly.
@ -130,20 +130,22 @@ class TeleBot:
Do not call this function more than once! Do not call this function more than once!
Always get updates. Always get updates.
:param none_stop: Do not stop polling when Exception occur.
:return: :return:
""" """
self.__stop_polling = False 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.daemon = True
self.polling_thread.start() self.polling_thread.start()
def __polling(self): def __polling(self, none_stop):
print('TeleBot: Started polling.') print('TeleBot: Started polling.')
while not self.__stop_polling: while not self.__stop_polling:
try: try:
self.get_update() self.get_update()
except Exception as e: except Exception as e:
print("TeleBot: Exception occurred. Stopping.") print("TeleBot: Exception occurred. Stopping.")
if not none_stop:
self.__stop_polling = True self.__stop_polling = True
print(e) print(e)