python - multiprocessing Pool, run in different directory for each items in list -
i using multiprocessing.pool module in code, using pool.map() function run items in list in parallel, want create separate working directory each items in list when pool.map function executed. list items contains models , simulated in simulate function. code looks
items=['bouncingball.mo','helloworld.mo'] multiprocessing import pool multiprocessing.dummy import pool threadpool pool = threadpool() pool.map(parallel,items) def simulate(lists): np='some directory path' os.chdir(np) model.simulate(lists)
the simulate function simulate each model in list , generate result files, want execute items in list in different directories, tried os.chdir(), creates 2 directories results stored in 1 directory both models, how execute result files in 2 different directories.is possible create different directories each process , execute seperately
this call:
os.chdir(np)
affects threads (and main thread) since belong same process.
you should open files written using full path rather changing directory globally.
if you'd use real processes wouldn't happen since you'd have different processes after implicit fork
calls.
your options are:
- do serially.
- use processes instead of threads
- provide path store results parameter (if possible) , use it.
seems you'll have pick 1 or 2.
Comments
Post a Comment