New to multiprocessing in python and just trying to understand why my code won't go inside the 'with Pool(processes=4) as pool: block. Here is a simple code (I removed some details because they are not necessary).
import os
import psutil
import time
import datetime
import sys
import multiprocessing
from multiprocessing.pool import Pool
import random as rnd
import math as math
from itertools import repeat
def test_func(arg1, arg2, arg3, arg4):
do something()
if __name__ == '__main__':
arg1 = sys.argv[1]
arg2 = int(sys.argv[2])
arg3 = int(sys.argv[3])
arg4 = int(sys.argv[4])
result_list = []
print("Setting up pool")
with Pool(processes=8) as pool:
print("Pool is set up")
pool.starmap_async(test_func, zip(arg1, repeat(arg2), repeat(arg3), repeat(arg4)), chunksize=3)
pool.close()
pool.join()
print("The end in pool")
print("The end in __main__")
Normally in all the circumstances I would expect it to go into the line print("pool is set up"). But occasionally it does not even go there and stops at print("Setting up pool"). Can anyone explain under what condition this might happen?