Last active
November 30, 2018 22:03
-
-
Save danemacaulay/0e049fff9f65d95dbd4334d94bc1893c to your computer and use it in GitHub Desktop.
python background scheduler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import threading | |
import datetime | |
class Scheduler(object): | |
def __init__(self, hours, job): | |
self.interval = datetime.timedelta(hours=hours).seconds | |
self.job = job | |
thread = threading.Thread(target=self.run, args=()) | |
thread.daemon = True | |
thread.start() | |
def run(self): | |
while True: | |
self.job() | |
time.sleep(self.interval) |
Author
danemacaulay
commented
Nov 30, 2018
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment