[Multiprocessing-sig] subprocess.Popen(...).communicate()[0] no longer works with multiprocessing.Pool

Hseu-Ming Chen hseuming at gmail.com
Thu Jun 9 21:35:33 CEST 2011


Hi,
I am having an issue when making a shell call from within a
multiprocessing.Process().  Here is the story: i tried to parallelize
the computations in 800-ish Matlab scripts and save the results to
MySQL.   The non-parallel/serial version has been running fine for
about 2 years.  However, in the parallel version via multiprocessing
that i'm working on, it appears that the Matlab scripts have never
been kicked off and nothing happened with subprocess.Popen.  The debug
printing below does not show up either.

Moreover, even if i replace the Matlab invocation with some trivial
"sed" call, still nothing happens.

Is it possible that the Python interpreter i'm using (version 2.6
released on Oct. 1, 2008) is too old?   Nevertheless, i would like to
make sure the basic framework i've now is not blatantly wrong.

Below is a skeleton of my Python program:

----------------------------------------------
import subprocess
from multiprocessing import Pool

def worker(DBrow,config):
    #  run one Matlab script
    cmd1 = "/usr/local/bin/matlab  ...  myMatlab.1.m"
    subprocess.Popen([cmd1], shell=True,
stdout=subprocess.PIPE).communicate()[0]
    print "this does not get printed"

    cmd2 = "sed ..."
    print subprocess.Popen(cmd2, shell=True,
stdout=subprocess.PIPE).communicate()[0]
    print "this does not get printed either"
    sys.stdout.flush()

###   main program below
......
# kick off parallel processing
pool = Pool()
for DBrow in DBrows: pool.apply_async(worker,(DBrow,config))
pool.close()
pool.join()
......
----------------------------------------------

Furthermore, i also tried adding the following:
   multiprocessing.current_process().curr_proc.daemon = False
at the beginning of the "worker" function above but to no avail.

Any help would really be appreciated.


More information about the Multiprocessing-sig mailing list