I'm using Schedule module in python, for scheduling my code so for that i used While True -
And here i have four Schedule time.
schedule.every().day.at(schedule_time).do(run_code)
while True:
schedule.run_pending()
time.sleep(2)
and i'm running this code with the help of Telegram. with the help of Telepot module
def handle(msg):
text_data = msg['text']
if (text_data == 'Start):
message = initial_message()
bot.sendMessage(1753352834, "Schedule Code starts running")
# Schedule_code function is calling for run my entire main code
schedule_code()
else:
bot.sendMessage(1753352834, "Sorry, I don't understand your mean, you should write Start")
MessageLoop(bot, handle).run_as_thread()
When i writes on telegram start so this code starts run, but i want to stop this code with the help of Telegram but i don't understand how.
I don't know how can i stop this While true function- I want, When i write Stop on telegram so my entire code would stop.
if (text_data == 'Stop):
sys.exit()
else:
pass
If you want to quit your program you could use
If you only want to go outside of the loop you could use
But the best way to do it is with a condition. You could use something like