python 多进程报错:Can‘t pickle<function ISC>
作者:互联网
各位大佬好,我在使用python多进程的时候遇到了一个问题
def multi_process():
# with ProcessPoolExecutor() as pool:
# pool = mp.Pool(mp.cpu_count())
with mp.Pool() as pool:
pool.starmap(ISC, [(l, t) for l in range(2 * brCount) for t in range(Time)])
if __name__ == "__main__":
for_start = time.time()
multi_process()
for_end = time.time()
函数ISC定义为:
def ISC(l, t):
global ISCR_C
ISCR_C[:, 0] = ISCR_A[l, :]
ISCR_C[:, 1] = ISCR_Pmax
ISCR_C = ISCR_C[np.lexsort(-ISCR_C[:, ::-1].T)]
if l <= brCount - 1:
for k in range(GenCount - 1):
if ISCR1(k, t) * ISCR2(k, t) * ISCR3(l, k, t) == 1:
opt.remove_constraint(model.branch_Cap1[t, l])
break
else:
for k in range(GenCount - 1):
if ISCR1(k, t) * ISCR2(k, t) * ISCR3(l, k, t) == 1:
opt.remove_constraint(model.branch_Cap2[t,l - brCount])
break
程序运行会报错:
第一次用多进程,除了问题也不知咋回事,有没有大佬能救救孩子
标签:function,__,ISCR,python,报错,mp,time,ISC,pool 来源: https://blog.csdn.net/zbx200057/article/details/122050171