Skip to content

Instantly share code, notes, and snippets.

@justinmoon
Created August 14, 2018 23:13
Show Gist options
  • Save justinmoon/f8ca45ef591c37259a56ea7f229151f0 to your computer and use it in GitHub Desktop.
Save justinmoon/f8ca45ef591c37259a56ea7f229151f0 to your computer and use it in GitHub Desktop.
Python: How to subclass threading.Thread
import random
import threading
import time
class MyThread(threading.Thread):
def run(self):
seconds = random.random()
print(f"sleeping for {seconds} seconds")
time.sleep(seconds)
print(f"waking")
if __name__ == "__main__":
for i in range(3):
t = MyThread()
t.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment