Skip to content

Instantly share code, notes, and snippets.

@ilstar
Created December 16, 2014 23:02
Show Gist options
  • Save ilstar/32e265b36337828bc8f4 to your computer and use it in GitHub Desktop.
Save ilstar/32e265b36337828bc8f4 to your computer and use it in GitHub Desktop.
Python Ticker or thresholding
from gevent import monkey;monkey.patch_all()
import gevent
import time
import logging
logging.basicConfig( level=logging.INFO, format="%(asctime)-15s %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
def timer(seconds, func):
while True:
logging.info('tick..')
gevent.spawn(func)
time.sleep(seconds)
def task():
logging.info("work start")
time.sleep(2)
logging.info("work done")
timer(5, task)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment