diff --git a/bot.py b/bot.py index 65cbfad..f014708 100644 --- a/bot.py +++ b/bot.py @@ -216,12 +216,20 @@ def check_thread(uid): def thread_supervisor(): while True: for uid in vk_tokens.scan_iter(): - if check_thread(uid.decode("utf-8")): - try: - create_thread(uid.decode("utf-8"), vk_tokens.get(uid)) - except requests.exceptions.ReadTimeout as e: - time.sleep(10) - time.sleep(120) + tries = 0 + while check_thread(uid.decode("utf-8")): + if tries < 6: + try: + create_thread(uid.decode("utf-8"), vk_tokens.get(uid)) + except: + tries = tries + 1 + else: + mark = types.InlineKeyboardMarkup() + login = types.InlineKeyboardButton('ВХОД', url=link) + mark.add(login) + bot.send_message(uid.decode("utf-8"), 'Непредвиденная ошибка, требуется повторный логин ВК!', + parse_mode='HTML', reply_markup=mark) + time.sleep(60) supervisor = threading.Thread(name='supervisor', target=thread_supervisor) diff --git a/vk_messages.py b/vk_messages.py index fb9566c..4755be0 100644 --- a/vk_messages.py +++ b/vk_messages.py @@ -26,8 +26,9 @@ class VkPolling: updates = vk_user.get_new_messages() if updates: handle_updates(vk_user, bot, chat_id, updates) - except requests.exceptions.ReadTimeout as e: - logging.warning('Retrying VK Polling in {} seconds.'.format(int(timeout / 10))) + except requests.exceptions.ReadTimeout: + logging.warning('Retrying VK Polling.') + timeout = 0 for i in range(timeout): if self._running: time.sleep(0.1)