Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
1,219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. def call_repeatedly(interval, func, *args, **kwargs):
  2.     stopped = Event()
  3.     def loop():
  4.         while not stopped.wait(interval):  # the first call is in `interval` secs
  5.             try:
  6.                 func(*args)
  7.             except Exception as e:
  8.                 logger.error(e);
  9.                 if kwargs.get('exception'):
  10.                     kwargs.get('exception')(e) # SEND exception to the specified function if there is one.
  11.                 else:
  12.                     raise Exception(e)
  13.     Thread(target=loop).start()
  14.     return stopped.set
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement