Created
October 29, 2018 11:48
-
-
Save sankalpjonn/ef748211fa73b0e14cd14b71eb1fa33d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
from timeloop import Timeloop | |
from datetime import timedelta | |
tl = Timeloop() | |
@tl.job(interval=timedelta(seconds=2)) | |
def sample_job_every_2s(): | |
print "2s job current time : {}".format(time.ctime()) | |
@tl.job(interval=timedelta(seconds=5)) | |
def sample_job_every_5s(): | |
print "5s job current time : {}".format(time.ctime()) | |
@tl.job(interval=timedelta(seconds=10)) | |
def sample_job_every_10s(): | |
print "10s job current time : {}".format(time.ctime()) | |
if __name__ == "__main__": | |
tl.start(block=True) | |
#Output: | |
#2s job current time : Tue Oct 16 17:55:35 2018 | |
#2s job current time : Tue Oct 16 17:55:37 2018 | |
#5s job current time : Tue Oct 16 17:55:38 2018 | |
#2s job current time : Tue Oct 16 17:55:39 2018 | |
#2s job current time : Tue Oct 16 17:55:41 2018 | |
#10s job current time : Tue Oct 16 17:55:43 2018 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instead of defining each job manually, I would like to use a factory pattern (or something similar) to setup 10 jobs. However, I am having some troubles setting them up. I was wondering if you can give me a hand.
Here are what I have done so far. I have identified two main problems. Please see the comments below.
All comments and suggestions are all highly appreciated. Thanks!