Created
April 1, 2013 22:38
-
-
Save zarch/5288362 to your computer and use it in GitHub Desktop.
using multiprocessing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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