Skip to content

Instantly share code, notes, and snippets.

@goutomroy
Created July 21, 2019 19:43
Show Gist options
  • Save goutomroy/85f3fe345f7775d3b649542ad06c5f03 to your computer and use it in GitHub Desktop.
Save goutomroy/85f3fe345f7775d3b649542ad06c5f03 to your computer and use it in GitHub Desktop.
import time
import random
from multiprocessing import Process
class Processor(Process):
def __init__(self, number):
Process.__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):
t = Processor(i)
t.start()
print("Total 5 Processes 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