Windows Python Passing Variables to Pool Processes -


i have python 2.7 program converts audiobook files. since there's bunch (100-300) of flac files, , have shiny, new computer i7 processor, i'm working on multiprocessing version of program.

i list of files using glob, create list of tuples...

fis = [] fi in globlist:   fis.append[(fi, author, title, year, genre)] 

i use pool.map(convert, fis) , program works. way faster old one-at-a-time version.

is there way create tuple (author, title, year, genre) in main function , have available convert function? dictionary fine, too. doesn't work if use global variables because guess child-processes don't inherit parent in windows. i'd rather not have several hundred copies of in files list, or waste time recreating in every child-process.

thanks.

you can try use initializer function pool(). instance that:

import multiprocessing mp  def initializer(myvariable):     global myvariable  if __name__ == "__main__":     fis = []     fi in globlist:         fis.append[(fi, author, title, year, genre)]     mp.pool(initializer=initializer, initargs=fis) pool:         pool.map(convert, fis) 

now convert should able see variable called myvariable fis list in present case. reason should work (i have not tested code not have windows python installation @ hand) each spawned process runs initializer. hope helps.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -