I am facing some issues while using concurrent.futures Multiprocess module.
import sys
import ConfigParser
import os
import concurrent.futures
from Script_A import get_list, AnalyzeRow #
rec_list = get_rec_list(MODE)
with concurrent.futures.ProcessPoolExecutor(max_workers=4) as executor:
for result in executor.map(AnalyzeRow, rec_list):
print str(result) # This is just for testing
EDIT:
Functions I import from Script_A
def get_rec_list(mode):
rowBank = []
current_row = 0
if mode == 'A':
setup_logging()
logging.debug("start")
create_playlist()
playlist_url= os.path.join(output_dir+"\\"+test_name, txtplaylist_name)
if not os.path.exists(playlist_url):
raise RuntimeError('playlist creation error')
with open(playlist_url, 'rb') as input_ctrl_csv:
ref_csv = csv.reader(input_ctrl_csv, delimiter=",")
for row in ref_csv:
if current_row > 0:
row.append(current_row)
rowBank.append(row)
current_row += 1
elif mode == 'B':
setup_logging()
logging.debug("start")
playlist_url = os.path.join(sig_dir, sigplaylist_name)
if not os.path.exists(playlist_url):
raise RuntimeError('sig playlist error.')
with open(playlist_url, 'rb') as sig_list:
ref_csv = csv.reader(sig_list, delimiter=";")
for row in ref_csv:
if current_row > 0:
row.append(current_row)
rowBank.append(row)
current_row += 1
else:
raise RuntimeError('invalid run mode')
return rowBank
def AnalyzeRow(row):
#This function makes some math to check if the values extracted from the
csv are inside a certain area range
generateData(row)
Error = getError(row)
return Error
I am aware that Python makes a previous run of the modules that are being imported into my current code, but when I execute the function AnalyzeRow inside the multiprocess function, it recalls to the line where I make the import of AnalyzeRow and get_rec_list functions and runs everything that is in between again, but I don't get any result.
EDIT: When I run my script, it gets to the executor.map(AnalyzeRow, rec_list)
line and it jumps back to line from Script_A import get_list, AnalyzeRow
so it will execute rec_list = get_rec_list(MODE)
3 more times, since I am using 4 processors. When I execute my code, I get in python interactive window 3 "starts" printed, which corresponds to get_rect_list()
function
Is there a better way I could do this execution or is there an error in my code that calls the multiprocess in a wrong way?