Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import wraps, partial
- def runforever(f, interval_secs=5):
- @wraps(f)
- def wrapper(*args, **kwds):
- while True:
- f(*args, **kwds)
- time.sleep(interval_secs)
- def runner(interval_secs, *args, **kwds):
- t = threading.Thread(target=wrapper, *args, **kwds)
- t.daemon = True
- t.start()
- wrapper = partial(wrapper)
- runner = partial(runner, interval_secs=interval_secs)
- return runner
- # this decorator with run your function in seperate thread after each interval_secs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement