B
B
bluefasik2022-01-23 15:27:33
Python
bluefasik, 2022-01-23 15:27:33

How to stop loop on click of inline button in aiogram?

I have 2 inline buttons. One starts the cycle, and the other must stop it.

bot.py

loop = StartLoop()
if call.data == 'start_loop':
    loop.start()
elif call.data == 'stop_loop':
    loop.stop()

loopbot.py

class StartLoop():
    def __init__(self):
        self.loopflag = True
    def start(self):
        while self.loopflag:
            <do something>
    def stop(self):
        self.loopflag = False

How to make this construction work without using global variables?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2022-01-23
@Vindicar

Do you have a multi-threaded bot? Because otherwise the only main thread will be busy with the cycle, and the bot will have no time to communicate with the cart server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question