Here is my user defined function
yms = ['201901', '201902', '201903', '201904', '201905', .... , '201812']
def minc(ym):
print('MINC %s %s\n' %(ym, str(datetime.datetime.now())))
print('value %s is in PID : %s \n' %(ym, os.getpid()))
t = datetime.datetime.now()
minc1 = pd.read_sql("""
select substring(MINC_IN_YM, 1, 4) as YEAR, substring(MINC_IN_YM, 5, 2) as MONTH,
count(MINC_INSP_NO) as NROWS,
sum(MINC_OKQTY) as TOTAL_QUANTITY,
sum(MINC_AV_PRICE*MINC_OKQTY) as TOTAL_DOLLARS
from dwadm.W_MINC
where MINC_INC_INF in ('RN', 'CN')
and MINC_ACCID in ('A', 'G', 'V')
and MINC_IN_YM = '%s'
and substring(MINC_BRNCD, 1, 1) not in ('S', 'C')
GROUP BY YEAR, MONTH, MINC_BRNCD, MINC_BRNCD_WHS, MINC_VNDCD, MINC_PTNO
""" % ym, conn)
print('MINC ends %s1 %s\n' %(ym, str(datetime.datetime.now()), str(datetime.datetime.nows())
return minc1
and I wanna do multiprocessing with function 'minc()' with below function 'parallelized()'
def parallelized():
if __name__ == '__main__' :
pool = Pool(processes = 8)
df = pool.map(minc, yms)
pool.close()
pool.join()
parallelized()
or
if __name__ == '__main__':
freeze_support()
t1 = time.time()
pool = Pool(8)
pool.map(minc, yms)
pool.close()
pool.join()
But when I run these above codes, these codes do not stop. They are infinitely running... I can't know how to solve this problem. When I use not my user defined function 'minc()' but use 'sum()' or any other basic functions, I could realize that parallel processing was executed well. Is there any other solutions for executing parallel processing of user-defined functions well?
Please help me!! :(
It is an OUTPUT when parallelized() function was executed.
MINC 201902 2020-11-03 08:15:23.469221
MINC 201901 2020-11-03 08:15:23.469228
MINC 201903 2020-11-03 08:15:23.469482
MINC 201904 2020-11-03 08:15:23.469703
MINC 201905 2020-11-03 08:15:23.469915
MINC 201906 2020-11-03 08:15:23.470106
MINC 201907 2020-11-03 08:15:23.470283
value 201902 is in PID : 1222
MINC 201908 2020-11-03 08:15:23.470459
value 201901 is in PID : 1221
value 201903 is in PID : 1223
value 201904 is in PID : 1224
value 201905 is in PID : 1225
value 201906 is in PID : 1226
value 201907 is in PID : 1227
value 201908 is in PID : 1228
MINC 201909 2020-11-03 08:15:23.489395
value 201909 is in PID : 1222