Skip to content

Instantly share code, notes, and snippets.

@codeslord
Created May 22, 2019 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeslord/9d1cd74fc868c055d5104999d40ac1d4 to your computer and use it in GitHub Desktop.
Save codeslord/9d1cd74fc868c055d5104999d40ac1d4 to your computer and use it in GitHub Desktop.
import threading
import time
class ThreadingExample(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=1):
""" Constructor
:type interval: int
:param interval: Check interval, in seconds
"""
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:
# Do something
print('Doing something imporant in the background')
time.sleep(self.interval)
example = ThreadingExample()
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