Files
Python-for-Geeks/Chapter07/multiprocessing/process7.py
T
muassif 3a0dab2f58 wrapping python code in main()
The code will not give error on Windows OS if wrapped inside the main function.
2021-08-14 14:33:10 +04:00

22 lines
521 B
Python

# process7.py to show synchronization and locking
from functools import partial
from multiprocessing import Pool, Manager
def printme (lock, msg):
lock.acquire()
try:
print(msg)
finally:
lock.release()
def main():
with Pool(3) as proc:
lock = Manager().Lock()
func = partial(printme,lock)
proc.map(func, ["Orange", "Apple", "Banana",
"Grapes","Pears"])
print("Exiting the main process")
if __name__ == '__main__':
main()