title: Scheduling Python Script to run every hour accurately
body: <p>Before I ask, <strong>Cron Jobs and Task Scheduler</strong> will be my last options, this script will be used across Windows and Linux and I'd prefer to have a coded out method of doing this than leaving this to the end user to complete.</p>
  <p>Is there a library for Python that I can use to schedule tasks? I will need to run a function once every hour, however, over time if I run a script once every hour and use .sleep, &quot;once every hour&quot; will run at a different part of the hour from the previous day due to the delay inherent to executing/running the script and/or function.</p>
  <p>What is the <strong>best</strong> way to schedule a function to run at a specific time of day (more than once) <em>without</em> using a Cron Job or scheduling it with Task Scheduler?</p>
  <p><em>Or if this is not possible, I would like your input as well.</em></p>
  <h2><strong>AP Scheduler fit my needs exactly.</strong></h2>
  <h3>Version &lt; 3.0</h3>
  <pre><code>import datetime
  import time
  from apscheduler.scheduler import Scheduler
  
  # Start the scheduler
  sched = Scheduler()
  sched.daemonic = False
  sched.start()
  
  def job_function():
      print(&quot;Hello World&quot;)
      print(datetime.datetime.now())
      time.sleep(20)
  
  # Schedules job_function to be run once each minute
  sched.add_cron_job(job_function,  minute='0-59')
  </code></pre>
  <p>out:</p>
  <pre><code>&gt;Hello World
  &gt;2014-03-28 09:44:00.016.492
  &gt;Hello World
  &gt;2014-03-28 09:45:00.0.14110
  </code></pre>
  <h3>Version &gt; 3.0</h3>
  <p>(From Animesh Pandey's answer below)</p>
  <pre><code>from apscheduler.schedulers.blocking import BlockingScheduler
  
  sched = BlockingScheduler()
  
  @sched.scheduled_job('interval', seconds=10)
  def timed_job():
      print('This job is run every 10 seconds.')
  
  @sched.scheduled_job('cron', day_of_week='mon-fri', hour=10)
  def scheduled_job():
      print('This job is run every weekday at 10am.')
  
  sched.configure(options_from_ini_file)
  sched.start()
  </code></pre>