Created
August 23, 2019 07:55
-
-
Save jwestarb/1d2c6df9a2e8a2763ab3f2a869340e37 to your computer and use it in GitHub Desktop.
Python Interval Runner
This file contains hidden or 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 threading import Thread | |
| from time import sleep | |
| class IntervalRunner(Thread): | |
| def __init__(self, interval, function, *args, **kwargs): | |
| Thread.__init__(self) | |
| #super(self, IntervalRunner).__init__(self) | |
| self.interval = interval | |
| self.function = function | |
| self.args = args | |
| self.kwargs = kwargs | |
| self.executing = False | |
| def run(self): | |
| self.executing = True | |
| while self.executing: | |
| self.function(*self.args, **self.kwargs) | |
| sleep(self.interval) | |
| def stop(self): | |
| self.executing = False | |
| dev executa(): | |
| print 'Executou' | |
| if __name__ == '__main__': | |
| print 'Checando a cada um minuto a quantidade de usuarios ativos' | |
| print 'Atencao: esse programa NUNCA termina.' | |
| interval_monitor = IntervalRunner(60, executa) | |
| interval_monitor.start() | |
| interval_monitor.join() # Opcional |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment