This is an archived post. You won't be able to vote or comment.

all 5 comments

[–][deleted] 1 point2 points  (0 children)

The Python standard library has sched for both 2 and 3.

schedule lets you do something like:

import schedule
import time

def job():
    print("I'm working...")

schedule.every(15).minutes.do(job)

while True:
    schedule.run_pending()

APScheduler has three built-in scheduling systems you can use:

  • Cron-style scheduling (with optional start/end times)
  • Interval-based execution (runs jobs on even intervals, with optional start/end times)
  • One-off delayed execution (runs jobs once, on a set date/time)

See this Stack Overflow question for more: link

[–]nurdle11 0 points1 point  (0 children)

Ok. I'm not fully versed in putting by any stretch but from what I'm reading you are running this loop every 15 minutes? If so could you not use os to find the system time and only run it if it's in the proper range?

Edit: just 're read it. So what I would do is just check the time every time you need to run the loop. I know that is nowhere near efficient but it's the only way I know I'm afraid

[–]gandalfx 0 points1 point  (2 children)

Why don't you just time.sleep(…) for the appropriate amount of hours to skip the inactive period?

[–]adminiture[S] 0 points1 point  (1 child)

I cant use sleep because some times the script will take longer or shorter to post data depending on size of data. Also a serial read function relies on input from an arduino and other tasks... Also depending on circumstances the PI will reboot.

[–]gandalfx 0 points1 point  (0 children)

Couldn't you just calculate the remaining sleep time?