From 82838e1d26bd26ff967fc5fbc4bdbf4f217fbb98 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Thu, 14 Jan 2021 03:44:37 +0300 Subject: [PATCH] Infinity polling fall down fixed --- telebot/__init__.py | 4 +++- telebot/apihelper.py | 2 +- telebot/util.py | 8 +++++--- telebot/version.py | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index f166a27..af5309d 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -6,6 +6,7 @@ import re import sys import threading import time +import traceback logger = logging.getLogger('TeleBot') formatter = logging.Formatter( @@ -459,7 +460,8 @@ class TeleBot: try: self.polling(none_stop=True, timeout=timeout, long_polling_timeout=long_polling_timeout, *args, **kwargs) except Exception as e: - logger.error("Infinity polling exception: {}".format(e)) + logger.error("Infinity polling exception: %s", str(e)) + logger.debug("Exception traceback:\n%s", traceback.format_exc()) time.sleep(3) continue logger.info("Infinity polling: polling exited") diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 1cedbc8..00763e0 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -254,7 +254,7 @@ def get_updates(token, offset=None, limit=None, timeout=None, allowed_updates=No if limit: payload['limit'] = limit if timeout: - payload['timeout'] = timeout + payload['connect-timeout'] = timeout if long_polling_timeout: payload['long_polling_timeout'] = long_polling_timeout if allowed_updates is not None: # Empty lists should pass diff --git a/telebot/util.py b/telebot/util.py index 713cbc3..1226ecc 100644 --- a/telebot/util.py +++ b/telebot/util.py @@ -235,8 +235,10 @@ def or_clear(self): def orify(e, changed_callback): - e._set = e.set - e._clear = e.clear + if not hasattr(e, "_set"): + e._set = e.set + if not hasattr(e, "_clear"): + e._clear = e.clear e.changed = changed_callback e.set = lambda: or_set(e) e.clear = lambda: or_clear(e) @@ -244,7 +246,7 @@ def orify(e, changed_callback): def OrEvent(*events): or_event = threading.Event() def changed(): - bools = [e.is_set() for e in events] + bools = [ev.is_set() for ev in events] if any(bools): or_event.set() else: diff --git a/telebot/version.py b/telebot/version.py index 31a8e24..2400619 100644 --- a/telebot/version.py +++ b/telebot/version.py @@ -1,3 +1,3 @@ # Versions should comply with PEP440. # This line is parsed in setup.py: -__version__ = '3.7.5' +__version__ = '3.7.5.u1'