So, I want to iterate over a pandas df in parallel so suppose i am having 15 rows then i want to iterate over it parallel and not one by one.
df:-
df = pd.DataFrame.from_records([ {'domain':'dnd','duration':'90','media_file':'testfont.wav','user':'tester_food','channel':'confctl-2' }, {'domain':'hrpd','duration':'90','media_file':'testfont.wav','user':'tester_food','channel':'confctl-2' }, {'domain':'blhp','duration':'90','media_file':'testfont.wav','user':'tester_food','channel':'confctl-2' }, {'domain':'rbswp','duration':'90','media_file':'testfont.wav','user':'tester_food','channel':'confctl-2' }, {'domain':'foxbp','duration':'90','media_file':'testfont.wav','user':'tester_food','channel':'confctl-2' }, {'domain':'rbsxbp','duration':'90','media_file':'testfont.wav','user':'tester_food','channel':'confctl-2' }, {'domain':'dnd','duration':'90','media_file':'testfont.wav','user':'tester_food','channel':'confctl-2' }, {'domain':'hrpd','duration':'90','media_file':'testfont.wav','user':'tester_food','channel':'confctl-2' } ]) So, I am iterating over the df and making command line and then storing the output in a df and doing data filtering and then finally storing it into influxdb. The problem is i am doing it one by one as i am iterating over it. what i want to iterate over all the rows in parallel.
As of now i have made 20 scripts and using multiprocessing to go over all the scripts in parallel. Its a pain when i have to do a change as i have to do it in all 20 scripts. My script looks like below :-
for index, row in dff.iterrows(): domain = row['domain'] duration = str(row['duration']) media_file = row['media_file'] user = row['user'] channel = row['channel'] cmda = './vaa -s https://' + domain + '.www.vivox.com/api2/ -d ' + duration + ' -f ' + media_file + ' -u .' + user + '. -c sip:confctl-2@' + domain + '.localhost.com -ati 0ps-host -atk 0ps- test' rows = [shlex.split(line) for line in os.popen( cmda).read().splitlines() if line.strip()] df = pd.DataFrame(rows) """ Bunch of data filteration and pushing it into influx """ As of now i am having 15 script if i am hvaing 15 rows in df and doing parallel processing like below :-
import os import time from multiprocessing import Process os.chdir('/Users/akumar/vivox-sdk-4.9.0002.30719.ebb523a9') def run_program(cmd): # Function that processes will run os.system(cmd) # Creating command to run commands = ['python testv.py'] commands.extend(['python testv{}.py'.format(i) for i in range(1, 15)]) # Amount of times your programs will run runs = 1 for run in range(runs): # Initiating Processes with desired arguments running_programs = [] for command in commands: running_programs.append(Process(target=run_program, args=(command,))) running_programs[-1].daemon = True # Start our processes simultaneously for program in running_programs: program.start() # Wait untill all programs are done while any(program.is_alive() for program in running_programs): time.sleep(1) Question:- How Can i iterate over the df and make all the 15 rows to run in parallel and do all the stuff inside the for loop.
