An infinite loop in a separate thread python telebot?

Have code like this:

from config import URL, PROXY, TOKEN
import telebot
from sqlite_module import *
import time
from threading import Thread

telebot.apihelper.proxy = {'https': PROXY}
bot = telebot.TeleBot(TOKEN)

# User is logged in the database for the UID and writes the name of the series, the request is processed in the database with the corresponding episode/s are added to the favorites table for that user.
# Here the question using a loop to add multiple series in a row

def start(message):
 tupp = (, message.from_user.username, message.from_user.first_name, message.from_user.last_name, time.ctime())
 send = bot.send_message(, 'What series do you search?')
 bot.register_next_step_handler(send, add_to_fav)

def add_to_fav(message):
 msg = search_in_db(message.text,
 if msg == 'No match found':
 bot.send_message(, msg)
 text = '@' + message.from_user.username + '' + 'Next series added to favorites: '
 bot.send_message(, text)
 for elem in msg:
 bot.send_message(, elem[1] + ': '+ elem[2])

# handler team will make a request to the DB and return list of episodes for the user in the presence of
def show(message):
 # print(message)
 # print(type(message))
 msg = show_user_info(
 if msg == 'No series in favorites':
 bot.send_message(, msg)
 text = '@' + message.from_user.username + '' + 'List favorites series: '
 bot.send_message(, text)
 for elem in msg:
 bot.send_message(, elem[0] + ': '+ elem[1])

# handler team runs the function in a separate thread to repeatedly check for updates published series
def download(message):
 bot.register_next_step_handler(message, thread_loop)

# start in separate thread task
def thread_loop(message):
 Thread(target=main_body, args=(message,)).start()

# here a cycle is called a witness for update RSS feeds when updating a forms dictionary {series: link} and sends it to the download
def main_body(message):
 last_update = "
 while True:
 if last_update != parsing_rss(URL).updated:
 last_update = parsing_rss(URL).updated
 d = parsing_rss(URL)
 result_parsing = d.entries
 series_list = {search_block_symbols(x['title']): x['link'] for x in result_parsing if x['tags'][0]['term'] == '[MP4]'}
 series_list_name_en = {key[key.find('(') + 1:key.find(')')]: value for key, value in series_list.items()}

#Yes Yes, yet another long polling, web hooks later.

if __name__ == '__main__':

Sqlite_module module contains functions to create / check in the DB, parsing RSS and download.
If you remove the telebot, the loop and all functions work as they should. Add user and list series, check update and jump.

Tell me where to look, and if we read for a coffee break, I hope you are flooded with a code) you Need to check function lived "separately" from the rest of the handlers could be invoked for each user separately.
April 3rd 20 at 18:31
2 answers
April 3rd 20 at 18:33
import threading

def async_function():
threading.Timer(5.0, f).start() # Restart in 5 seconds
print("Hello, world!")

April 3rd 20 at 18:35
A separate thread to run the function I implemented, but to convey a message from the handler in the flow is not clear :( save to database and send to check_rss_in_fav() - elody_Gottlieb75 commented on April 3rd 20 at 18:38

Find more questions by tags PythonmultithreadingBotsTelegram