Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def call_repeatedly(interval, func, *args, **kwargs):
- stopped = Event()
- def loop():
- while not stopped.wait(interval): # the first call is in `interval` secs
- try:
- func(*args)
- except Exception as e:
- logger.error(e);
- if kwargs.get('exception'):
- kwargs.get('exception')(e) # SEND exception to the specified function if there is one.
- else:
- raise Exception(e)
- Thread(target=loop).start()
- return stopped.set
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement