Why does python stop at the output of the python subprocess?

I use Python subprocess.call () to run a series of python scripts, each of which runs Matlab scripts. The problem is when the first Matlab script ends.

An external Python script parses the csv file directory for settings to run experiments based on each line of csv files. For each experiment, it calls a python program to run data analysis and feed into Matlab. Matlab then launches each experiment. Except that the whole thing comes out after the first launch of Matlab. Can Matlab get out of its subprocess to reduce all this?

for line in csvfile: if debug: print 'Experiment %d' % count ts = line.split(',') startStamp=ts[0] cmdargs = ['python prep_lssvm.py'] cmdargs.append(str(site)) cmdargs.append(str(startStamp)) cmdargs.append(str(daysTraining)) if debug: print cmdargs for i in range(len(argv)-2): cmdargs.append(str(argv[i+2])) command = ' '.join(cmdargs) if debug: print command call(command,shell=True) #Never goes past here<<<<<<======================= dirname = ''.join([site,'_',str(count)]) mkdir(dirname) call(''.join(['mv ',site,'/*.txt ',dirname]),shell=True,stdout=outfile) 
+4
source share
1 answer

It seems I solved this by debugging the rubber duck.

I called MATLAB script through Popen (), which is executed asynchronously, and not call (), which is executed synchronously. Changing all instances of Popen to call seems to have solved the problem.

0
source

Source: https://habr.com/ru/post/1438334/


All Articles