Created
September 26, 2016 06:01
-
-
Save exhuma/429602945094152a4632aa0bd767b902 to your computer and use it in GitHub Desktop.
Example of running functions at given time intervals.
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
from time import sleep | |
import logging | |
LOG = logging.getLogger(__name__) | |
def every_5_seconds(): | |
LOG.info('Running every 5') | |
def every_3_seconds(): | |
LOG.info('Running every 3') | |
def every_1_minutes(): | |
LOG.info('Running every minute') | |
def main(): | |
elapsed_seconds = 0 | |
while True: | |
LOG.info('tick #%d', elapsed_seconds) | |
if elapsed_seconds % 5 == 0: | |
every_5_seconds() | |
if elapsed_seconds % 3 == 0: | |
every_3_seconds() | |
if elapsed_seconds % 60 == 0: | |
every_1_minutes() | |
sleep(1) | |
elapsed_seconds += 1 | |
if __name__ == '__main__': | |
logging.basicConfig( | |
format='%(asctime)s | %(levelname)s | %(message)s', | |
level=logging.DEBUG | |
) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment