Python Forum

Full Version: Is my pi sleeping or hanging up?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I was getting a warning on my mac terminal

Error:
WARNING:apscheduler.executors.default:Run time of job "timed_job (trigger: interval[1:00:00], next run at: 2016-11-19 05:31:35 CST)" was missed by 0:56:34.651017
What is the context?
Im running it from an ssh terminal on my mac. At first I thought my mac going to sleep was causing the problem but I dont think so because even if the mac goes to sleep, the rpi2 shouldnt. The script is scheduled to fetch data from the web every hour indefinitely. Can anyone tell me if its wrong to make the rpi2 run a scheduled job indefinitely?

Here is the code:

# class to hold read and write
#!/usr/bin/env python
import serial
import logging
import time, datetime
from firebase import firebase
from firebase_token_generator import create_token
from apscheduler.schedulers.blocking import BlockingScheduler

class AIHome:

	def __init__(self, onTime, offTime):
		self.onTime=onTime
		self.offTime=offTime
		self.updateInterval = 6
		self.webPush = False
		self.relayStatesA = []
		self.relayStatesD = {}
		logging.basicConfig()
		
		print('initting AIHome...scheduling job')
		sched = BlockingScheduler()
		@sched.scheduled_job('interval', hours=1)
		def timed_job():
			print('This job runs every 1 hrs. timed_job gets called or something else')
			self.fetchUpdate();		
		sched.configure()
		sched.start()
		 
	def fetchUpdate(self):
	    #Must separate credentials
		AIHome.authentication = firebase.FirebaseAuthentication('mykey', '[email protected]', extra={'id': 123})
		AIHome.firebase = firebase.FirebaseApplication('https://myapp.firebaseio.com/', AIHome.authentication)
		print AIHome.authentication.extra
		AIHome.user = AIHome.authentication.get_user()
		print AIHome.user.firebase_auth_token
		AIHome.results = AIHome.firebase.get('/Relays', None)#, {'print': 'pretty'})
		print AIHome.results		
		print AIHome.results['Relay1ON']
		print AIHome.results['Relay1OFF']
		self.relayToggle()
		
	def relayToggle(self):
		timestring = AIHome.results['Relay1ON']
		print timestring
		hours,minutes = timestring.split(":")
		print hours
		print minutes
		print(datetime.datetime.now())
		ref_time = datetime.datetime.combine(datetime.datetime.now(), datetime.time(int(hours), int(minutes)))
		if ref_time > datetime.datetime.now():
			print("ref_time>relay should be OFF")
		else:
			print("now>relay should be ON")

x = AIHome(1,2)
Thanks in advance!
I edited the post title and code above to help describe the issue more clearly.
So does apscheduler use the system scheduler? Or does your script continue to run forever, and just not do anything most of the time?
What do you mean?