Skip to content

Instantly share code, notes, and snippets.

@goutomroy
Last active July 21, 2019 19:21
Show Gist options
  • Save goutomroy/7ba655452690acbfe1ad6993944fb635 to your computer and use it in GitHub Desktop.
Save goutomroy/7ba655452690acbfe1ad6993944fb635 to your computer and use it in GitHub Desktop.
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