Created
May 16, 2017 13:34
-
-
Save toast254/2cb84e21355227cf96964443ef0968e7 to your computer and use it in GitHub Desktop.
This file contains 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
# -*- coding: utf-8 -*- | |
import time | |
import threading | |
class ThreadedClass(object): | |
""" Threading example class. | |
The run() method will be started and it will run in the background | |
until the application exits. | |
""" | |
def __init__(self, interval: int = 1): | |
""" Constructor. | |
:type interval: int | |
:param interval: Check interval, in seconds, default 1 | |
""" | |
self.interval = interval | |
thread = threading.Thread(target=self.run, args=()) | |
thread.daemon = True # Daemonize thread | |
thread.start() # Start the execution | |
def run(self): | |
""" Method that runs forever. | |
""" | |
while True: | |
print('Hey lookt at me ! I do something in the background !!') | |
time.sleep(self.interval) | |
example = ThreadedClass() | |
time.sleep(3) | |
print('Checkpoint') | |
time.sleep(2) | |
print('Bye') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment