Answer the question
In order to leave comments, you need to log in
How to stop a thread when a command is entered?
def start_parser(message):
if db.get_temp_country(message.from_user.id) == 'pool':
pool = PoolUi()
thread_counter = Thread(target=pool.generate_link).start()
thread_counter = Thread(target=loading_advs(message).start()
Answer the question
In order to leave comments, you need to log in
The only sane way is that the body of the thread should check some condition from time to time (be it the threading.Event object, or just a boolean variable). Accordingly, if the condition is met, the body of the thread must immediately end without finishing what has been started.
If you do not control what happens in the body of the thread, and you cannot divide its work into separate small iterations (to check the condition in between), then there is no good solution.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question