Created
July 21, 2019 19:43
-
-
Save goutomroy/85f3fe345f7775d3b649542ad06c5f03 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 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