title: How to stop schedule multiple times and restart if needed. Python. Telebot
body: <p>I'm trying to make /stop command for the bot (the greetings stop to send). It works, but only one time, after pressing the /start command it is unable to stop again and runs forever.
  Tried different methods of stopping, manged either to stop and unable to restart or to stop once and unable to stop after repeating /start or &quot;greet&quot;.
  I would be very grateful for the advice of how to improve the existing code</p>
  <pre><code>    import random, telebot, schedule, time
  from telebot import types
  from config import token
  bot = telebot.TeleBot(token)
  
  greetings = [&quot;hello&quot;, &quot;Have a nice day&quot;, &quot;Goodbye&quot;, &quot;Wow&quot;]
  
  @bot.message_handler(commands=['start'])
  def start_message(message):
      markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
      item1 = types.KeyboardButton(&quot;Greet&quot;)
      markup.add(item1)
      bot.send_message(message.chat.id, &quot;Press button&quot;, reply_markup=markup)
  
  @bot.message_handler(content_types=[&quot;text&quot;])
  def run_function(message):
  
      def function_to_run():
          random_greet = random.choice(greetings)
          bot.send_message(message.chat.id, random_greet)
  
      def scheduling():
          schedule.every(4).seconds.do(function_to_run).tag('schedule')
      scheduling()
  
      if message.text.lower() == &quot;greet&quot;:
          bot.send_message(message.chat.id, &quot;here you go&quot;)
  
          function_to_run()
  
          def schedule_run():
              while True:
                  schedule.run_pending()
                  time.sleep(1)
          schedule_run()
  
      elif message.text.lower() == &quot;stop&quot;:
          bot.send_message(message.chat.id, &quot;stopping...&quot;)
          schedule.clear('schedule')
          time.sleep(1)
          bot.send_message(message.chat.id, &quot;stopped successfully&quot;)
  
  
  bot.polling()
  </code></pre>