Created
August 14, 2018 23:13
-
-
Save justinmoon/f8ca45ef591c37259a56ea7f229151f0 to your computer and use it in GitHub Desktop.
Python: How to subclass threading.Thread
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
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