Skip to content

Instantly share code, notes, and snippets.

@toast254
Created May 16, 2017 13:34
Show Gist options
  • Save toast254/2cb84e21355227cf96964443ef0968e7 to your computer and use it in GitHub Desktop.
Save toast254/2cb84e21355227cf96964443ef0968e7 to your computer and use it in GitHub Desktop.
# -*- 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