adding chapter 7 source code

This commit is contained in:
muassif
2021-03-31 09:22:38 +04:00
committed by GitHub
parent 9589675a50
commit f88527eef4
20 changed files with 618 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
# process2.py to create processes using a pool
import os
from multiprocessing import Process, Pool, current_process as cp
from time import sleep
def print_message(msg):
sleep(1)
print("{}-{}: {}".format(os.getpid(), cp().name, msg))
# creating process from a pool
with Pool(3) as proc:
proc.map(print_message, ["Orange", "Apple", "Banana",
"Grapes","Pears"])
print("Exiting the main process")