E
E
EnotShow2022-01-06 18:27:35
Python
EnotShow, 2022-01-06 18:27:35

How to stop the looped telegram bot function (telebot)?

I am writing a bot using the telebot library. How can you stop the execution of a looped function without catching an exception?

@bot.message_handler(commands=['start_scraping'])
    def sender(message):
        bot.send_message(
            message.chat.id,
            "Начал парсинг"
        )
        while True:
            bot_message = sent_to_user
            bot.send_message(message.chat.id, bot_message())

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vindicar, 2022-01-06
@Vindicar

In the specified form - no way, the bot, as far as I can tell, is single-threaded, and this one thread will be busy with the while True loop.

I
InternetMaster, 2022-01-06
@InternetMaster

Have breakn't heard of?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question