Last active
July 21, 2019 19:21
-
-
Save goutomroy/7ba655452690acbfe1ad6993944fb635 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
import time | |
import random | |
from threading import Thread | |
class Worker(Thread): | |
def __init__(self, number): | |
Thread.__init__(self) | |
self._number = number | |
def run(self): | |
sleep = random.randrange(1, 10) | |
time.sleep(sleep) | |
print(f"Worker {self._number}, slept for {sleep} seconds") | |
if __name__ == "__main__": | |
for i in range(1, 6): | |
task = Worker(i) | |
task.start() | |
print("Total 5 Threads are queued, let's see when they finish!") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment