title: How to use Schedule module with a conditional while loop in Python
body: <p>I'm trying to use the Schedule module to run a task during specific days of the week and specific hours, basically business hours. The while loop will work when the condition is true but once it's false it will not run again to see if the time frame still applies. I would have to restart the script for it to work.</p>
  
  <p>I'm pretty new to Python and self taught. This is my first time posting here so please correct me if I've formatted this badly or haven't included enough information. I've tried scouring the forums to get around this particular issue I'm having but haven't found an answer; I'm probably searching wrong. It may be a simple issue but I've been wracking my brain for a few days. This is a small test portion of code that I'm trying to use for another script. Other people have recommended Cron but since this is going into a larger script, I only need a section of it to run on a task and not the whole thing.</p>
  
  <pre><code>from datetime import datetime as dt
  import schedule
  import time
  
  def weekdayJob(x, i=None):
      week = dt.today().weekday()
      if i is not None and week &lt; 5 and dt.now().hour in range(9,17):
          schedule.every(i).minutes.do(x)
  
  def printJob():
      timestamp = time.strftime("%Y%m%d-%H%M")
      print(f"test {timestamp}\n")
  
  
  weekdayJob(printJob, 5)
  
  while True:
      schedule.run_pending()
      time.sleep(5)
  </code></pre>
  
  <p>I've also tried</p>
  
  <pre><code>from datetime import datetime as dt
  import schedule
  import time
  
  def weekdayJob(x, i=None):
      week = dt.today().weekday()
      if i is not None and week &lt; 5 and dt.now().hour in range(9,17):
          schedule.every(i).minutes.do(x)
  
  def printJob():
      timestamp = time.strftime("%Y%m%d-%H%M")
      print(f"test {timestamp}\n")
  
  x = 1
  while x == 1:
      weekdayJob(printJob, 1)
      time.sleep(5)
      while True:
          schedule.run_pending()
          time.sleep(5)
  </code></pre>
  
  <p>I figured that putting the scheduled job in the while loop would make it constantly check to see if the conditional statement was true but that doesn't seem the case. How would I make it so this script is constantly checking if weekdayJob is within the desired time frame so I don't have to restart the script.</p>