Попробуйте использовать пул из многопроцессорной системы:
from multiprocessing import Pool
def resolve(str_input, representation):
try:
import cirpy
res = cirpy.resolve(str_input, representation)
except:
res = "Error"
print('\r', str_input, res, end='')
return (str_input, res)
n = 5
with Pool(processes=n) as pool:
compounds_smiles_list = pool.starmap(resolve, [(row['Compound'], 'smiles') for index, row in df_Verteilung.iterrows()])
compound_list = [elem[0] for elem in compounds_smiles_list]
smiles_list = [elem[1] for elem in compounds_smiles_list]
df_new = pd.DataFrame({'Compound' : compound_list, 'SmilesCode' : smiles_list})
df_new.to_csv(index=False)
Используя переменную n
, вы управляете размером пула.Кроме того, вы можете оставить конструктор Pool пустым, и в соответствии с вашей системой будет выбрано оптимизированное количество рабочих.
Некоторые объяснения:
Пул
Starmap