- not using subprocesses (they are too low-level and OS-dependent) nor threads
import multiprocessing
def _parallel_search(i):
computed = _make_some_computations(i)
queue.put({"index": i, "computed": computed})
jobs = []
queue = multiprocessing.Queue()
for i in range(0, 5):
proc = multiprocessing.Process(target=_parallel_job, args=tuple(i))
jobs.append(proc)
proc.start()
# wait for jobs
for proc in jobs:
proc.join()
while not queue.empty():
print "Computation result for index %s is %s" % queue.get()