Answer the question
In order to leave comments, you need to log in
How to track the execution status of a script?
I am writing a telebot that processes links. When the user sends the link, the bot starts processing, it takes some time. If another link is dropped at this time, the bot will start processing the new one without finishing with the old one, which will lead to an error. I need to prevent new links from being accepted while the current one is being processed. How to do it better?
So far, I have come up with such a way, to create ACTIVE_STATUS = False
and put a check on the input of the function if ACTIVE_STATUS = False
. When processing starts, do ACTIVE_STATUS = True
, and change back at the output. ACTIVE_STATUS = False
But the studio highlights this section with an error:
if ACTIVE_STATUS == False:
ACTIVE_STATUS = True
Answer the question
In order to leave comments, you need to log in
Use a couple of queues and a separate thread for processing links.
The handler reads the description of the request (for example, the link and sender id) from the first queue, processes it, and puts the result into the second queue.
The main bot, when receiving a link, tries to put it in the first place (you can add a limit on the maximum queue size!). He should also look into the second queue from time to time. If there is something there, then extract the result of processing the link, and do what is required with it (for example, send it to the user).
The advantage of such a scheme is that you can run several handler threads, if the resources of the computer allow. But it will be necessary to think over the moment with their stop at the end of the bot.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question