Я использую многопроцессорность, потому что мой код очень медленный в пределах al oop. Мой код работает нормально, пока не дойдет до строки 240, а затем не работает, но я не знаю, в чем проблема и почему всегда терпит неудачу после итерации 240.
Я получаю следующую ошибку:
Вот основной файл
p = multiprocessing.Pool(4)
for i in range(total_rows):
print(i)
try:
kwargs = ds.iloc[i:i+1,1:].to_dict(orient = "records")
objPricing = Pricing(**kwargs[0])
engine = EngineService(objPricing).calculate(p)
engine['credit_card_number'] = ds.loc[i,'credit_card_number']
row = getRow(engine)
with open(stored_data_path, mode = 'a+',encoding = 'utf-8', newline='\n') as file:
writer = csv.writer(file)
writer.writerow(row)
except:
p.close()
p.join()
tarjeta = (ds.loc[i,'credit_card_number'])
with open(stored_data_path_error, mode = 'a+',encoding = 'utf-8', newline='\n') as file:
writer = csv.writer(file)
writer.writerow([tarjeta])
continue
p.close()
p.join()
Вот файл py, в котором я использую pool.
result = pool.map(self.optimization, line_range) # Here is POOL MAP
result = [ratios for ratios in result if ratios] # We clean list of None values
def optimization(self, value):
if value > self.avg_balance and value <= np.minimum((self.aux_credit_line*4), 50000):
self.outputs.results = pd.DataFrame()
self.inputs.credit_line = value
self.outputs.flg_optimization = 0
self.m_param.calculate()
self.m_cancellation.calculate()
self.m_balance.calculate()
self.m_balance_opt = ModBalanceOptimization(self.data.query(' MODULE == "balance_optimization" '), self.inputs, self.outputs, avg_balance= self.avg_balance)
self.m_balance_opt.calculate()
self.m_cash_flow.calculate_CashFlow_Variables() # apr_ep, apr_bt, apr_disef, apr_purchase
self.m_cash_flow.calculate_Balance_Composition_12()
self.m_credit_risk.calculate()
self.m_cash_flow.calculate_Survival()
self.m_cash_flow.calculate_Available_Balance() # Saldos Habiles
self.m_cash_flow.calculate_Implicit_Rate(flg_optimization = 1, aux_implicit_rate = self.aux_implicit_rate)
self.m_financial.calculate()
self.m_ecap.calculate()
self.outputs.flg_array_van_opt = 1
self.m_cash_flow.calculate_Complete_Cash_Flow_In_Sequence()
Я получаю ошибку
Exception in thread Thread-3:
Traceback (most recent call last):
File "C:\Program Files\Python36\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Program Files\Python36\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\Program Files\Python36\lib\multiprocessing\pool.py", line 463, in _handle_results
task = get()
File "C:\Program Files\Python36\lib\multiprocessing\connection.py", line 251, in recv
return _ForkingPickler.loads(buf.getbuffer())
TypeError: __init__() missing 1 required positional argument: 'is_local'