Skip to content

Instantly share code, notes, and snippets.

@zarch
Created April 1, 2013 22:38
Show Gist options
  • Save zarch/5288362 to your computer and use it in GitHub Desktop.
Save zarch/5288362 to your computer and use it in GitHub Desktop.
using multiprocessing
import multiprocessing as mltp
def work(x, y):
return x * y
def worker(queue):
while True:
args = queue.get()
if args is None: break
work(*args)
NPROC = 4
queue = mltp.Queue()
# populate the queue
for pair in zip(range(100), range(100, 200)):
print pair
queue.put(pair)
for _ in range(NPROC):
queue.put(None)
pool = mltp.Pool(processes=NPROC)
pool.map_async(worker, (queue, ) * NPROC)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment