I was developing a scheduling application, in the schedule there's many lamp that turn on and off in specific time, say if I start the schedule at morning all lamps will turn on then stop at night, but there is some lamp that need to stop at random time and also turn on again. I've tried some python package like APScheduler but it doesn't have feature to stop and resume a specific task (or lamp in this occasion).
This question using pickle to stop and resume, but I don't know how to implement it, is there any way to solve this?
Thanks in advance, sorry for my bad grammer.
--UPDATE--
Here is simple implementation, I'm not sure this code is right.
from datetime import datetime
from time import sleep
class Scheduling:
def __init__(self):
self.lamp = {}
def run(self, lamp_id, start, finish):
"""Called one-time only for each lamp"""
self.lamp[lamp_id] = (start, finish)
while True:
if datetime.now().strftime('%H:%M:%S') == start:
sleep(1)
print 'SET LAMP %s ON' % lamp_id
elif datetime.now().strftime('%H:%M:%S') == finish:
sleep(1)
print 'SET LAMP %s OFF' % lamp_id
def stop(self, lamp_id):
print 'SET lamp %s OFF' % lamp_id
def resume(self, lamp_id):
print 'SET lamp %s ON' % lamp_id
finish = self.lamp[lamp_id][1]
while True:
if datetime.now().strftime('%H:%M:%S') == finish:
print 'SET lamp %s OFF' % lamp_id
if __name__ == '__main__':
schedule = Scheduling()
schedule.run(1, '00:00:00', '00:01:00')