H
H
Hector Synchrome2021-07-01 14:49:36
Python
Hector Synchrome, 2021-07-01 14:49:36

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 = Falseand 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

Perhaps there are ideas how to solve this? Or maybe there is some way that is better than the one I came up with?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-07-01
@MatewGreg

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 question

Ask a Question

731 491 924 answers to any question