Alternative use patterns for python multiprocessing avoiding proliferation of global state?
问题 This (enormously simplified example) works fine (Python 2.6.6, Debian Squeeze): from multiprocessing import Pool import numpy as np src=None def process(row): return np.sum(src[row]) def main(): global src src=np.ones((100,100)) pool=Pool(processes=16) rows=pool.map(process,range(100)) print rows if __name__ == "__main__": main() however, after years of being taught global state bad!!! , all my instincts are telling me I really really would rather be writing something closer to: from